-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from vertexcover-io/feat/tests
Add tests and github actions
- Loading branch information
Showing
13 changed files
with
518 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Run-tests | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
permissions: | ||
contents: read | ||
jobs: | ||
unit: | ||
strategy: | ||
matrix: | ||
go: ['1.23.2'] | ||
os: [ubuntu-latest, macos-latest, windows-latest] | ||
fail-fast: true | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Go ${{ matrix.go }} | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: ${{ matrix.go }} | ||
cache: false | ||
|
||
- name: Run Tests | ||
run: go test -race -cover -coverprofile=coverage -covermode=atomic -v ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package locatr | ||
package core | ||
|
||
import ( | ||
"fmt" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package core | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestContentStr(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
element ElementSpec | ||
expected string | ||
}{ | ||
{ | ||
name: "Single element with no attributes or children", | ||
element: ElementSpec{ | ||
ID: "1", | ||
TagName: "div", | ||
Text: "Hello World", | ||
}, | ||
expected: `<div id="1">Hello World</div>`, | ||
}, | ||
{ | ||
name: "Element with attributes", | ||
element: ElementSpec{ | ||
ID: "2", | ||
TagName: "span", | ||
Text: "Hello", | ||
Attributes: map[string]string{ | ||
"class": "greeting", | ||
"style": "color: red;", | ||
}, | ||
}, | ||
expected: `<span class="greeting" style="color: red;" id="2">Hello</span>`, | ||
}, | ||
{ | ||
name: "Element with children", | ||
element: ElementSpec{ | ||
ID: "3", | ||
TagName: "ul", | ||
Children: []ElementSpec{ | ||
{ | ||
ID: "4", | ||
TagName: "li", | ||
Text: "Item 1", | ||
}, | ||
{ | ||
ID: "5", | ||
TagName: "li", | ||
Text: "Item 2", | ||
}, | ||
}, | ||
}, | ||
expected: `<ul id="3"><li id="4">Item 1</li><li id="5">Item 2</li></ul>`, | ||
}, | ||
{ | ||
name: "Element with attributes and children", | ||
element: ElementSpec{ | ||
ID: "6", | ||
TagName: "div", | ||
Attributes: map[string]string{ | ||
"class": "container", | ||
}, | ||
Children: []ElementSpec{ | ||
{ | ||
ID: "7", | ||
TagName: "p", | ||
Text: "Paragraph", | ||
}, | ||
}, | ||
}, | ||
expected: `<div class="container" id="6"><p id="7">Paragraph</p></div>`, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
result := tt.element.ContentStr() | ||
if result != tt.expected { | ||
t.Errorf("got %s, want %s", result, tt.expected) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.