diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..a6a95a2 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,42 @@ +name: build + +on: + workflow_dispatch: + push: + branches: + - 'master' + tags: + - 'v*' + pull_request: + +jobs: + Building: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + # https://github.com/actions/virtual-environments#available-environments + os: [ubuntu-latest] + steps: + - name: Checkout out source code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + submodules: 'true' + - name: Set up Go environment + uses: actions/setup-go@v5 + with: + go-version-file: 'go.mod' + id: go + + - name: Cache Go modules + uses: actions/cache@v4 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: make build + run: | + go test -v diff --git a/parser.go b/parser.go index feb7afc..e4ff88b 100644 --- a/parser.go +++ b/parser.go @@ -198,8 +198,6 @@ func parse(l *list.List) (map[Rule]map[string]string, error) { styles[style] = value } } - - continue } css[r] = styles @@ -209,6 +207,7 @@ func parse(l *list.List) (map[Rule]map[string]string, error) { styles = map[string]string{} style, value = "", "" isBlock = false + rule = make([]string, 0) } prevToken = token.typ() } diff --git a/parser_test.go b/parser_test.go index dc37bc8..57c2d3c 100644 --- a/parser_test.go +++ b/parser_test.go @@ -78,7 +78,6 @@ rule { t.Fatal("should error out") } }) - } func TestParseHarder(t *testing.T) { @@ -104,6 +103,14 @@ rule2 { if _, ok := css["rule2"]; !ok { t.Fatal("missing rule 'rule2'") } + + if len(css["rule1"]) != 2 { + t.Fatalf("expected 2 styles for rule 'rule1', got %d", len(css["rule1"])) + } + + if len(css["rule2"]) != 1 { + t.Fatalf("expected 1 style for rule 'rule2', got %d", len(css["rule2"])) + } }) t.Run("PropertyWithSpace", func(t *testing.T) { ex1 := `body { @@ -149,7 +156,6 @@ rule1 { if err != nil { t.Fatal(err) } - }) } @@ -195,11 +201,9 @@ func TestParseSelectorGroup(t *testing.T) { if _, ok := css["rule3"]; !ok { t.Fatal("Missing '.rule3' rule") } - } func BenchmarkParser(b *testing.B) { - ex1 := "" for i := 0; i < 100; i++ { ex1 += fmt.Sprintf(`block%d {