116 lines
3.1 KiB
Go
116 lines
3.1 KiB
Go
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, "<strong>Item Code:</strong>") {
|
|
t.Error("Item Code should be bolded")
|
|
}
|
|
|
|
if !strings.Contains(output, "<strong>Item Description:</strong>") {
|
|
t.Error("Item Description should be bolded")
|
|
}
|
|
|
|
// Check that list items are in <ol><li> tags
|
|
if !strings.Contains(output, "<ol>") {
|
|
t.Error("Ordered list should have <ol> tag")
|
|
}
|
|
|
|
if !strings.Contains(output, "<li>-4 deg C</li>") {
|
|
t.Error("List item 1 not formatted correctly")
|
|
}
|
|
|
|
// Check that italic patterns are applied
|
|
if !strings.Contains(output, "<em>See attached EC Conformity Declaration for the SE Sensor</em>") {
|
|
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, "<strong>")
|
|
strongCloses := strings.Count(output, "</strong>")
|
|
if strongOpens != strongCloses {
|
|
t.Errorf("Unbalanced <strong> tags: %d opens, %d closes", strongOpens, strongCloses)
|
|
}
|
|
|
|
emOpens := strings.Count(output, "<em>")
|
|
emCloses := strings.Count(output, "</em>")
|
|
if emOpens != emCloses {
|
|
t.Errorf("Unbalanced <em> tags: %d opens, %d closes", emOpens, emCloses)
|
|
}
|
|
|
|
olOpens := strings.Count(output, "<ol>")
|
|
olCloses := strings.Count(output, "</ol>")
|
|
if olOpens != olCloses {
|
|
t.Errorf("Unbalanced <ol> 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", "<strong>Item Code:</strong>"},
|
|
{"Type: SE - To control", "<strong>Type:</strong>"},
|
|
{"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)
|
|
}
|
|
}
|
|
}
|