MCPcopy Create free account
hub / github.com/github/gh-aw / TestFrontmatterOffsetCalculation

Function TestFrontmatterOffsetCalculation

pkg/parser/integration_test.go:83–144  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

81}
82
83func TestFrontmatterOffsetCalculation(t *testing.T) {
84 // Test frontmatter at the beginning of the file
85 tempFile := "/tmp/gh-aw/gh-aw/test_frontmatter_offset.md"
86
87 // Ensure the directory exists
88 err := os.MkdirAll(filepath.Dir(tempFile), 0755)
89 if err != nil {
90 t.Fatalf("Failed to create temp directory: %v", err)
91 }
92
93 content := `---
94name: Test Workflow
95invalid_prop: bad
96---
97
98# This is content after frontmatter
99<!-- HTML comment -->
100
101Content here.
102`
103
104 err = os.WriteFile(tempFile, []byte(content), 0644)
105 if err != nil {
106 t.Fatalf("Failed to create temp file: %v", err)
107 }
108 defer os.Remove(tempFile)
109
110 schemaJSON := `{
111 "type": "object",
112 "properties": {
113 "name": {"type": "string"}
114 },
115 "additionalProperties": false
116 }`
117
118 frontmatterResult, err := ExtractFrontmatterFromContent(content)
119 if err != nil {
120 t.Fatalf("Failed to extract frontmatter: %v", err)
121 }
122
123 err = validateWithSchemaAndLocation(frontmatterResult.Frontmatter, schemaJSON, "test workflow", tempFile)
124
125 if err == nil {
126 t.Fatal("Expected validation error for additional properties, got nil")
127 }
128
129 errorMessage := err.Error()
130 t.Logf("Error message with offset: %s", errorMessage)
131
132 // The invalid_prop should be on line 3 (1-based: ---, name, invalid_prop)
133 expectedPatterns := []string{
134 tempFile + ":",
135 "3:", // Line 3 where invalid_prop appears
136 "invalid_prop",
137 }
138
139 for _, pattern := range expectedPatterns {
140 if !strings.Contains(errorMessage, pattern) {

Callers

nothing calls this directly

Calls 4

ErrorMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected