package pdf import ( "strings" "testing" ) func TestFormatDescription(t *testing.T) { input := `Item Code: B25SEZ22B0 Item Description: SE Sensor Zone 22 Type: SE - To control the function of the rupture disc Cable Length: 2m Ui< 40V li<57mA Li, Ci negligible II 2G Ex ib IIC T6 (Gb) II 2D Ex ib IIC T 80 deg C IP65 ((Db) -25 deg C < Ta < +80 deg C IBEx U1ATEX1017 Includes installation instruction With standard Angle Bracket to suit Brilex Non-Insulated Explosion Vents (If Insulated panels are used a modified (vertically extended) bracket needs to be used) See attached EC Conformity Declaration for the SE Sensor Testing at 1. -4 deg C 2. -30 deg C 3. 20 deg C` output := formatDescription(input) // Check that key: value pairs are bolded if !strings.Contains(output, "Item Code:") { t.Error("Item Code should be bolded") } if !strings.Contains(output, "Item Description:") { t.Error("Item Description should be bolded") } // Check that list items are in
  1. tags if !strings.Contains(output, "
      ") { t.Error("Ordered list should have
        tag") } if !strings.Contains(output, "
      1. -4 deg C
      2. ") { t.Error("List item 1 not formatted correctly") } // Check that italic patterns are applied if !strings.Contains(output, "See attached EC Conformity Declaration for the SE Sensor") { t.Error("Italic pattern not applied to EC Conformity Declaration text") } // Verify HTML tags are properly balanced (count opening/closing tag pairs) strongOpens := strings.Count(output, "") strongCloses := strings.Count(output, "") if strongOpens != strongCloses { t.Errorf("Unbalanced tags: %d opens, %d closes", strongOpens, strongCloses) } emOpens := strings.Count(output, "") emCloses := strings.Count(output, "") if emOpens != emCloses { t.Errorf("Unbalanced tags: %d opens, %d closes", emOpens, emCloses) } olOpens := strings.Count(output, "
          ") olCloses := strings.Count(output, "
        ") if olOpens != olCloses { t.Errorf("Unbalanced
          tags: %d opens, %d closes", olOpens, olCloses) } t.Logf("Formatted output:\n%s", output) } func TestIsOrderedListItem(t *testing.T) { tests := []struct { input string expected bool }{ {"1. Item one", true}, {"2. Item two", true}, {"10. Item ten", true}, {"Item without number", false}, {"1 Item without dot", false}, {"Item: with colon", false}, } for _, test := range tests { result := isOrderedListItem(test.input) if result != test.expected { t.Errorf("isOrderedListItem(%q) = %v, want %v", test.input, result, test.expected) } } } func TestFormatLine(t *testing.T) { tests := []struct { input string contains string }{ {"Item Code: B25SEZ22B0", "Item Code:"}, {"Type: SE - To control", "Type:"}, {"Random text here", "Random text here"}, } for _, test := range tests { result := formatLine(test.input) if !strings.Contains(result, test.contains) { t.Errorf("formatLine(%q) should contain %q, got %q", test.input, test.contains, result) } } }