diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 73d7a5114..9f84f9938 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,12 +3,36 @@ name: build on: [push, pull_request] jobs: + analyze: + name: Static Analysis + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: '>=1.19' + + - name: Set up linters + run: make install-tools + + - name: Lint + run: | + make vet + make lint + make fmt + git diff + if [[ $(git diff) != '' ]]; then echo 'Invalid formatting!' >&2; exit 1; fi + build: name: Build runs-on: ubuntu-latest strategy: matrix: - goVer: [1.14, 1.15, 1.16, 1.17] + goVer: [1.18, 1.19] steps: - name: Set up Go ${{ matrix.goVer }} uses: actions/setup-go@v2 @@ -16,14 +40,17 @@ jobs: go-version: ${{ matrix.goVer }} id: go + - name: Check out code into the Go module directory + uses: actions/checkout@v2 + - name: Set up ANTLR env: - ANTLR_VERSION: 4.9 + ANTLR_VERSION: 4.11.1 run: | sudo curl -o /usr/local/lib/antlr-${ANTLR_VERSION}-complete.jar https://www.antlr.org/download/antlr-${ANTLR_VERSION}-complete.jar export CLASSPATH=".:/usr/local/lib/antlr-${ANTLR_VERSION}-complete.jar:$CLASSPATH" mkdir $HOME/antlr-bin - echo -e '#!/bin/bash\njava -jar /usr/local/lib/antlr-4.9-complete.jar "$@"' > $HOME/antlr-bin/antlr + echo -e '#!/bin/bash\njava -jar /usr/local/lib/antlr-4.11.1-complete.jar "$@"' > $HOME/antlr-bin/antlr echo -e '#!/bin/bash\njava org.antlr.v4.gui.TestRig "$@"' > $HOME/antlr-bin/grun chmod +x $HOME/antlr-bin/* export PATH=$PATH:$HOME/antlr-bin @@ -32,25 +59,12 @@ jobs: - name: Set up Lab run: | curl https://raw.githubusercontent.com/MontFerret/lab/master/install.sh -o install.sh - sudo sh install.sh - - - name: Set up linters - run: go get -u github.com/mgechev/revive - - - name: Check out code into the Go module directory - uses: actions/checkout@v2 + chmod +x ./install.sh + LOCATION=$PWD ./install.sh - name: Get dependencies run: make install - - name: Lint - run: | - make vet - make lint - make fmt - git diff - if [[ $(git diff) != '' ]]; then echo 'Invalid formatting!' >&2; exit 1; fi - - name: Generate run: | export PATH=$PATH:$HOME/antlr-bin @@ -65,5 +79,5 @@ jobs: - name: E2E tests run: | docker run -d -p 9222:9222 ghcr.io/montferret/chromium:92.0.4512.0 - make e2e + LAB_BIN=$PWD/lab make e2e docker stop $(docker ps -q) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 2305be2b0..85ee8e63e 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -17,8 +17,6 @@ on: pull_request: # The branches below must be a subset of the branches above branches: [ master ] - schedule: - - cron: '44 5 * * 4' jobs: analyze: @@ -34,34 +32,34 @@ jobs: # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed steps: - - name: Checkout repository - uses: actions/checkout@v2 + - name: Checkout repository + uses: actions/checkout@v2 - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v1 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - # queries: ./path/to/local/query, your-org/your-repo/queries@main + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v1 + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v1 - # âšī¸ Command-line programs to run using the OS shell. - # đ https://git.io/JvXDl + # âšī¸ Command-line programs to run using the OS shell. + # đ https://git.io/JvXDl - # âī¸ If the Autobuild fails above, remove it and uncomment the following three lines - # and modify them (or add more) to build your code if your project - # uses a compiled language + # âī¸ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language - #- run: | - # make bootstrap - # make release + #- run: | + # make bootstrap + # make release - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bec6501c..88a2edf43 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,44 @@ ## Changelog +### 0.16.6 + +### Fixed +- Invalid XPath evaluation in HTTP driver [#725](https://github.com/MontFerret/ferret/pull/725) +- Go routines leakage [#726](https://github.com/MontFerret/ferret/pull/726) + +### Updated +- Small tweak in FQL Parser for FQL Formatter [#723](https://github.com/MontFerret/ferret/pull/723) + +### 0.16.5 + +### Fixed +- Query fails if an element is not found (regression) [#722](https://github.com/MontFerret/ferret/pull/722) + +### Updated +- Small tweak in FQL Parser for FQL Formatter [#723](https://github.com/MontFerret/ferret/pull/723) + +### 0.16.4 + +### Fixed +- Fixed inability to parse custom date formats with DATE function [#720](https://github.com/MontFerret/ferret/pull/720) + +### 0.16.3 + +### Fixed +- Panic during XPath execution by HTTP driver [#715](https://github.com/MontFerret/ferret/pull/715) + +### 0.16.2 + +### Fixed +- Unable to use dynamic values in LIMIT clause [#706](https://github.com/MontFerret/ferret/pull/706) +- HTTP driver does not allow to override header values [#707](https://github.com/MontFerret/ferret/pull/707), [#709](https://github.com/MontFerret/ferret/pull/709) +- Cleaned up deps [#710](https://github.com/MontFerret/ferret/pull/710), [#711](https://github.com/MontFerret/ferret/pull/711) + +### 0.16.1 + +### Fixed +- Logical precedence in ternary operator condition [#704](https://github.com/MontFerret/ferret/pull/704) + ### 0.16.0 ### Added diff --git a/Makefile b/Makefile index 0350e1873..bbabe7bc9 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,7 @@ .PHONY: build install compile test e2e doc fmt lint vet release +export CGO_ENABLED=0 +LAB_BIN ?= lab DIR_BIN = ./bin DIR_PKG = ./pkg DIR_E2E = ./e2e @@ -8,22 +10,27 @@ default: build build: vet generate test compile +install-tools: + go install honnef.co/go/tools/cmd/staticcheck@latest && \ + go install golang.org/x/tools/cmd/goimports@latest && \ + go install github.com/mgechev/revive@latest + install: go get compile: - go build -race -v -o ${DIR_BIN}/ferret \ + go build -v -o ${DIR_BIN}/ferret \ ${DIR_E2E}/cli.go test: - go test -race ${DIR_PKG}/... + go test ${DIR_PKG}/... cover: - go test -race -coverprofile=coverage.txt -covermode=atomic ${DIR_PKG}/... && \ + go test -coverprofile=coverage.txt -covermode=atomic ${DIR_PKG}/... && \ curl -s https://codecov.io/bash | bash e2e: - lab --timeout=120 --attempts=5 --concurrency=1 --wait=http://127.0.0.1:9222/json/version --runtime=bin://./bin/ferret --files=./e2e/tests --cdn=./e2e/pages/dynamic --cdn=./e2e/pages/static + ${LAB_BIN} --timeout=120 --attempts=5 --concurrency=1 --wait=http://127.0.0.1:9222/json/version --runtime=bin://./bin/ferret --files=./e2e/tests --cdn=./e2e/pages/dynamic --cdn=./e2e/pages/static bench: go test -run=XXX -bench=. ${DIR_PKG}/... @@ -36,11 +43,13 @@ doc: # http://golang.org/cmd/go/#hdr-Run_gofmt_on_package_sources fmt: - go fmt ${DIR_PKG}/... + go fmt ${DIR_PKG}/... && \ + goimports -w -local github.com/MontFerret ./pkg ./e2e # https://github.com/mgechev/revive # go get github.com/mgechev/revive lint: + staticcheck ./pkg/compiler ./pkg/drivers ./pkg/runtime ./pkg/stdlib && \ revive -config revive.toml -formatter stylish -exclude ./pkg/parser/fql/... -exclude ./vendor/... ./... # http://godoc.org/code.google.com/p/go.tools/cmd/vet diff --git a/e2e/cli.go b/e2e/cli.go index 5c0505796..0e12d4e61 100644 --- a/e2e/cli.go +++ b/e2e/cli.go @@ -7,6 +7,7 @@ import ( "encoding/json" "flag" "fmt" + "io" "io/ioutil" "os" "os/signal" @@ -114,21 +115,21 @@ func (p *Profiler) Print(label string) { timer, found := p.timers[label] if found { - fmt.Fprintln(writer, fmt.Sprintf("Time: %s", timer.end.Sub(timer.start))) + fmt.Fprintf(writer, "Time: %s\n", timer.end.Sub(timer.start)) } stats, found := p.allocs[label] if found { - fmt.Fprintln(writer, fmt.Sprintf("Alloc: %s", byteCountDecimal(stats.Alloc))) - fmt.Fprintln(writer, fmt.Sprintf("Frees: %s", byteCountDecimal(stats.Frees))) - fmt.Fprintln(writer, fmt.Sprintf("Total Alloc: %s", byteCountDecimal(stats.TotalAlloc))) - fmt.Fprintln(writer, fmt.Sprintf("Heap Alloc: %s", byteCountDecimal(stats.HeapAlloc))) - fmt.Fprintln(writer, fmt.Sprintf("Heap Sys: %s", byteCountDecimal(stats.HeapSys))) - fmt.Fprintln(writer, fmt.Sprintf("Heap Idle: %s", byteCountDecimal(stats.HeapIdle))) - fmt.Fprintln(writer, fmt.Sprintf("Heap In Use: %s", byteCountDecimal(stats.HeapInuse))) - fmt.Fprintln(writer, fmt.Sprintf("Heap Released: %s", byteCountDecimal(stats.HeapReleased))) - fmt.Fprintln(writer, fmt.Sprintf("Heap Objects: %d", stats.HeapObjects)) + fmt.Fprintf(writer, "Alloc: %s\n", byteCountDecimal(stats.Alloc)) + fmt.Fprintf(writer, "Frees: %s\n", byteCountDecimal(stats.Frees)) + fmt.Fprintf(writer, "Total Alloc: %s\n", byteCountDecimal(stats.TotalAlloc)) + fmt.Fprintf(writer, "Heap Alloc: %s\n", byteCountDecimal(stats.HeapAlloc)) + fmt.Fprintf(writer, "Heap Sys: %s\n", byteCountDecimal(stats.HeapSys)) + fmt.Fprintf(writer, "Heap Idle: %s\n", byteCountDecimal(stats.HeapIdle)) + fmt.Fprintf(writer, "Heap In Use: %s\n", byteCountDecimal(stats.HeapInuse)) + fmt.Fprintf(writer, "Heap Released: %s\n", byteCountDecimal(stats.HeapReleased)) + fmt.Fprintf(writer, "Heap Objects: %d\n", stats.HeapObjects) } //cpu, found := p.cpus[label] @@ -138,7 +139,7 @@ func (p *Profiler) Print(label string) { //} if writer.Len() > 0 { - fmt.Println(fmt.Sprintf("%s:", label)) + fmt.Printf("%s:\n", label) fmt.Println("-----") fmt.Println(writer.String()) } @@ -260,7 +261,7 @@ func main() { // check whether the app is getting a query via standard input std := bufio.NewReader(os.Stdin) - b, err := ioutil.ReadAll(std) + b, err := io.ReadAll(std) if err != nil { fmt.Println(err) @@ -440,7 +441,7 @@ func execQuery(ctx context.Context, engine *ferret.Instance, opts []runtime.Opti prof.PrintAll() if out != nil { - fmt.Println(fmt.Sprintf("Output size: %s", byteCountDecimal(uint64(len(out))))) + fmt.Printf("Output size: %s\n", byteCountDecimal(uint64(len(out)))) fmt.Println("") } } diff --git a/e2e/tests/dynamic/element/query/element_not_found_by_css.fql b/e2e/tests/dynamic/element/query/element_not_found_by_css.fql new file mode 100644 index 000000000..2e5d49832 --- /dev/null +++ b/e2e/tests/dynamic/element/query/element_not_found_by_css.fql @@ -0,0 +1,8 @@ +LET url = @lab.cdn.dynamic +LET doc = DOCUMENT(url, { driver: "cdp" }) + +LET el = ELEMENT(doc, "#do-not-exist") + +T::NONE(el) + +RETURN TRUE diff --git a/e2e/tests/dynamic/element/query/element_not_found_by_xpath.fql b/e2e/tests/dynamic/element/query/element_not_found_by_xpath.fql new file mode 100644 index 000000000..5ee8c35c9 --- /dev/null +++ b/e2e/tests/dynamic/element/query/element_not_found_by_xpath.fql @@ -0,0 +1,8 @@ +LET url = @lab.cdn.dynamic +LET doc = DOCUMENT(url, true) + +LET el = ELEMENT(doc, X("//*[@id='do-not-exist']"))? + +T::NONE(el) + +RETURN TRUE diff --git a/e2e/tests/dynamic/element/siblings/next_not_found.fql b/e2e/tests/dynamic/element/siblings/next_not_found.fql new file mode 100644 index 000000000..575088fe6 --- /dev/null +++ b/e2e/tests/dynamic/element/siblings/next_not_found.fql @@ -0,0 +1,8 @@ +LET doc = DOCUMENT(@lab.cdn.dynamic + "/#/lists", { driver:"cdp" }) + +LET current = ELEMENT(doc, "body") +T::NOT::NONE(current) +LET next = current.nextElementSibling +T::NONE(next) + +RETURN NONE \ No newline at end of file diff --git a/e2e/tests/dynamic/element/siblings/prev_not_found.fql b/e2e/tests/dynamic/element/siblings/prev_not_found.fql new file mode 100644 index 000000000..6d16a8809 --- /dev/null +++ b/e2e/tests/dynamic/element/siblings/prev_not_found.fql @@ -0,0 +1,8 @@ +LET doc = DOCUMENT(@lab.cdn.dynamic + "/#/lists", { driver:"cdp" }) + +LET current = ELEMENT(doc, 'head') +T::NOT::NONE(current) +LET prev = current.previousElementSibling +T::NONE(prev) + +RETURN NONE \ No newline at end of file diff --git a/e2e/tests/dynamic/element/xpath/attrs.fql b/e2e/tests/dynamic/element/xpath/attrs.fql new file mode 100644 index 000000000..fd7e8069e --- /dev/null +++ b/e2e/tests/dynamic/element/xpath/attrs.fql @@ -0,0 +1,8 @@ +LET url = @lab.cdn.dynamic +LET page = DOCUMENT(url, true) + +LET actual = XPATH(page, "//body/@class") + +T::NOT::EMPTY(actual) + +RETURN T::EQ(actual[0], "text-center") \ No newline at end of file diff --git a/examples/embedded/main.go b/examples/embedded/main.go index 97b5964af..6b26c1a5a 100644 --- a/examples/embedded/main.go +++ b/examples/embedded/main.go @@ -27,7 +27,7 @@ func main() { } for _, topic := range topics { - fmt.Println(fmt.Sprintf("%s: %s %s", topic.Name, topic.Description, topic.URL)) + fmt.Printf("%s: %s %s\n", topic.Name, topic.Description, topic.URL) } } diff --git a/examples/xpath.fql b/examples/xpath.fql new file mode 100644 index 000000000..b57888b7c --- /dev/null +++ b/examples/xpath.fql @@ -0,0 +1,5 @@ +LET doc = DOCUMENT("https://www.google.ca", { + driver: 'cdp' +}) + +RETURN XPATH(doc, "//meta/@charset") // ["UTF-8"] \ No newline at end of file diff --git a/pkg/compiler/compiler_array_test.go b/pkg/compiler/compiler_array_test.go index 216cc7c31..96921ea7a 100644 --- a/pkg/compiler/compiler_array_test.go +++ b/pkg/compiler/compiler_array_test.go @@ -2,9 +2,11 @@ package compiler_test import ( "context" - "github.com/MontFerret/ferret/pkg/compiler" - . "github.com/smartystreets/goconvey/convey" "testing" + + . "github.com/smartystreets/goconvey/convey" + + "github.com/MontFerret/ferret/pkg/compiler" ) func TestArrayOperator(t *testing.T) { diff --git a/pkg/compiler/compiler_cases_test.go b/pkg/compiler/compiler_cases_test.go index 7e52c4700..63f906b71 100644 --- a/pkg/compiler/compiler_cases_test.go +++ b/pkg/compiler/compiler_cases_test.go @@ -6,6 +6,9 @@ import ( "strings" "testing" + "golang.org/x/text/cases" + "golang.org/x/text/language" + "github.com/MontFerret/ferret/pkg/compiler" "github.com/MontFerret/ferret/pkg/stdlib/arrays" @@ -57,7 +60,8 @@ func TestCases(t *testing.T) { "Mixed": func(s string) string { // Capitalize string. // Source: https://stackoverflow.com/questions/33696034/make-first-letter-of-words-uppercase-in-a-string - return strings.Title(strings.ToLower(s)) + // return strings.Title(strings.ToLower(s)) + return cases.Title(language.English).String(strings.ToLower(s)) }, "Upper": strings.ToUpper, "Lower": strings.ToLower, diff --git a/pkg/compiler/compiler_collect_aggregate_test.go b/pkg/compiler/compiler_collect_aggregate_test.go index 28571a172..2616db03f 100644 --- a/pkg/compiler/compiler_collect_aggregate_test.go +++ b/pkg/compiler/compiler_collect_aggregate_test.go @@ -2,10 +2,12 @@ package compiler_test import ( "context" + "testing" + + . "github.com/smartystreets/goconvey/convey" + "github.com/MontFerret/ferret/pkg/compiler" "github.com/MontFerret/ferret/pkg/runtime" - . "github.com/smartystreets/goconvey/convey" - "testing" ) func TestAggregate(t *testing.T) { diff --git a/pkg/compiler/compiler_collect_count_test.go b/pkg/compiler/compiler_collect_count_test.go index c85cb3eba..20eb70517 100644 --- a/pkg/compiler/compiler_collect_count_test.go +++ b/pkg/compiler/compiler_collect_count_test.go @@ -2,10 +2,12 @@ package compiler_test import ( "context" + "testing" + + . "github.com/smartystreets/goconvey/convey" + "github.com/MontFerret/ferret/pkg/compiler" "github.com/MontFerret/ferret/pkg/runtime" - . "github.com/smartystreets/goconvey/convey" - "testing" ) func TestCollectCount(t *testing.T) { diff --git a/pkg/compiler/compiler_collect_into_test.go b/pkg/compiler/compiler_collect_into_test.go index 2ab6ccc1a..60fb1c82d 100644 --- a/pkg/compiler/compiler_collect_into_test.go +++ b/pkg/compiler/compiler_collect_into_test.go @@ -2,10 +2,12 @@ package compiler_test import ( "context" + "testing" + + . "github.com/smartystreets/goconvey/convey" + "github.com/MontFerret/ferret/pkg/compiler" "github.com/MontFerret/ferret/pkg/runtime" - . "github.com/smartystreets/goconvey/convey" - "testing" ) func TestCollectInto(t *testing.T) { diff --git a/pkg/compiler/compiler_collect_test.go b/pkg/compiler/compiler_collect_test.go index 9fa2dd1b3..991592c0b 100644 --- a/pkg/compiler/compiler_collect_test.go +++ b/pkg/compiler/compiler_collect_test.go @@ -2,10 +2,12 @@ package compiler_test import ( "context" + "testing" + + . "github.com/smartystreets/goconvey/convey" + "github.com/MontFerret/ferret/pkg/compiler" "github.com/MontFerret/ferret/pkg/runtime" - . "github.com/smartystreets/goconvey/convey" - "testing" ) func TestCollect(t *testing.T) { diff --git a/pkg/compiler/compiler_collect_with_count_test.go b/pkg/compiler/compiler_collect_with_count_test.go index f088d6680..7f44c3588 100644 --- a/pkg/compiler/compiler_collect_with_count_test.go +++ b/pkg/compiler/compiler_collect_with_count_test.go @@ -2,10 +2,12 @@ package compiler_test import ( "context" + "testing" + + . "github.com/smartystreets/goconvey/convey" + "github.com/MontFerret/ferret/pkg/compiler" "github.com/MontFerret/ferret/pkg/runtime" - . "github.com/smartystreets/goconvey/convey" - "testing" ) func TestCollectWithCount(t *testing.T) { diff --git a/pkg/compiler/compiler_eq_test.go b/pkg/compiler/compiler_eq_test.go index 59ba60e32..4ef9855d1 100644 --- a/pkg/compiler/compiler_eq_test.go +++ b/pkg/compiler/compiler_eq_test.go @@ -2,10 +2,12 @@ package compiler_test import ( "context" + "testing" + + . "github.com/smartystreets/goconvey/convey" + "github.com/MontFerret/ferret/pkg/compiler" "github.com/MontFerret/ferret/pkg/runtime" - . "github.com/smartystreets/goconvey/convey" - "testing" ) func TestEqualityOperators(t *testing.T) { diff --git a/pkg/compiler/compiler_filter_test.go b/pkg/compiler/compiler_filter_test.go index 96c3ca8bb..6893a35f4 100644 --- a/pkg/compiler/compiler_filter_test.go +++ b/pkg/compiler/compiler_filter_test.go @@ -2,11 +2,13 @@ package compiler_test import ( "context" + "testing" + + . "github.com/smartystreets/goconvey/convey" + "github.com/MontFerret/ferret/pkg/compiler" "github.com/MontFerret/ferret/pkg/runtime/core" "github.com/MontFerret/ferret/pkg/runtime/values" - . "github.com/smartystreets/goconvey/convey" - "testing" ) func TestForFilter(t *testing.T) { diff --git a/pkg/compiler/compiler_for_ternary_test.go b/pkg/compiler/compiler_for_ternary_test.go index 7935f5f8e..cbc0ab186 100644 --- a/pkg/compiler/compiler_for_ternary_test.go +++ b/pkg/compiler/compiler_for_ternary_test.go @@ -2,9 +2,11 @@ package compiler_test import ( "context" - "github.com/MontFerret/ferret/pkg/compiler" - . "github.com/smartystreets/goconvey/convey" "testing" + + . "github.com/smartystreets/goconvey/convey" + + "github.com/MontFerret/ferret/pkg/compiler" ) func TestForTernaryExpression(t *testing.T) { diff --git a/pkg/compiler/compiler_for_test.go b/pkg/compiler/compiler_for_test.go index c3b1561f9..1f938b138 100644 --- a/pkg/compiler/compiler_for_test.go +++ b/pkg/compiler/compiler_for_test.go @@ -3,11 +3,13 @@ package compiler_test import ( "context" "encoding/json" - "github.com/MontFerret/ferret/pkg/compiler" - "github.com/MontFerret/ferret/pkg/runtime" - . "github.com/smartystreets/goconvey/convey" "sort" "testing" + + . "github.com/smartystreets/goconvey/convey" + + "github.com/MontFerret/ferret/pkg/compiler" + "github.com/MontFerret/ferret/pkg/runtime" ) func TestFor(t *testing.T) { diff --git a/pkg/compiler/compiler_for_while_ternary_test.go b/pkg/compiler/compiler_for_while_ternary_test.go index af4931316..3bc06fc8c 100644 --- a/pkg/compiler/compiler_for_while_ternary_test.go +++ b/pkg/compiler/compiler_for_while_ternary_test.go @@ -2,11 +2,13 @@ package compiler_test import ( "context" + "testing" + + . "github.com/smartystreets/goconvey/convey" + "github.com/MontFerret/ferret/pkg/compiler" "github.com/MontFerret/ferret/pkg/runtime/core" "github.com/MontFerret/ferret/pkg/runtime/values" - . "github.com/smartystreets/goconvey/convey" - "testing" ) func TestForTernaryWhileExpression(t *testing.T) { diff --git a/pkg/compiler/compiler_for_while_test.go b/pkg/compiler/compiler_for_while_test.go index fe39809c0..2e8377bf8 100644 --- a/pkg/compiler/compiler_for_while_test.go +++ b/pkg/compiler/compiler_for_while_test.go @@ -2,12 +2,14 @@ package compiler_test import ( "context" + "testing" + + . "github.com/smartystreets/goconvey/convey" + "github.com/MontFerret/ferret/pkg/compiler" "github.com/MontFerret/ferret/pkg/runtime" "github.com/MontFerret/ferret/pkg/runtime/core" "github.com/MontFerret/ferret/pkg/runtime/values" - . "github.com/smartystreets/goconvey/convey" - "testing" ) func TestForWhile(t *testing.T) { diff --git a/pkg/compiler/compiler_func_ns_test.go b/pkg/compiler/compiler_func_ns_test.go index a51123e73..094b4cf73 100644 --- a/pkg/compiler/compiler_func_ns_test.go +++ b/pkg/compiler/compiler_func_ns_test.go @@ -3,13 +3,15 @@ package compiler_test import ( "context" "fmt" + "regexp" + "testing" + + . "github.com/smartystreets/goconvey/convey" + "github.com/MontFerret/ferret/pkg/compiler" "github.com/MontFerret/ferret/pkg/parser" "github.com/MontFerret/ferret/pkg/runtime/core" "github.com/MontFerret/ferret/pkg/runtime/values" - . "github.com/smartystreets/goconvey/convey" - "regexp" - "testing" ) func TestFunctionNSCall(t *testing.T) { @@ -101,7 +103,7 @@ func TestFunctionNSCall(t *testing.T) { p := parser.New("RETURN TRUE") c := compiler.New() - r := regexp.MustCompile("\\w+") + r := regexp.MustCompile(`\w+`) for _, l := range p.GetLiteralNames() { if r.MatchString(l) { diff --git a/pkg/compiler/compiler_func_test.go b/pkg/compiler/compiler_func_test.go index 4ca3d5d73..50a51cda7 100644 --- a/pkg/compiler/compiler_func_test.go +++ b/pkg/compiler/compiler_func_test.go @@ -2,12 +2,14 @@ package compiler_test import ( "context" + "testing" + + "github.com/pkg/errors" + . "github.com/smartystreets/goconvey/convey" + "github.com/MontFerret/ferret/pkg/compiler" "github.com/MontFerret/ferret/pkg/runtime/core" "github.com/MontFerret/ferret/pkg/runtime/values" - "github.com/pkg/errors" - . "github.com/smartystreets/goconvey/convey" - "testing" ) func TestFunctionCall(t *testing.T) { diff --git a/pkg/compiler/compiler_in_test.go b/pkg/compiler/compiler_in_test.go index d1f6da606..9c7d312d4 100644 --- a/pkg/compiler/compiler_in_test.go +++ b/pkg/compiler/compiler_in_test.go @@ -2,9 +2,11 @@ package compiler_test import ( "context" - "github.com/MontFerret/ferret/pkg/compiler" - . "github.com/smartystreets/goconvey/convey" "testing" + + . "github.com/smartystreets/goconvey/convey" + + "github.com/MontFerret/ferret/pkg/compiler" ) func TestInOperator(t *testing.T) { diff --git a/pkg/compiler/compiler_let_test.go b/pkg/compiler/compiler_let_test.go index cc17c6166..2a5c3e6a5 100644 --- a/pkg/compiler/compiler_let_test.go +++ b/pkg/compiler/compiler_let_test.go @@ -2,12 +2,14 @@ package compiler_test import ( "context" + "testing" + + . "github.com/smartystreets/goconvey/convey" + "github.com/MontFerret/ferret/pkg/compiler" "github.com/MontFerret/ferret/pkg/runtime" "github.com/MontFerret/ferret/pkg/runtime/core" "github.com/MontFerret/ferret/pkg/runtime/values" - . "github.com/smartystreets/goconvey/convey" - "testing" ) func TestLet(t *testing.T) { diff --git a/pkg/compiler/compiler_like_test.go b/pkg/compiler/compiler_like_test.go index 14542a7a0..991c1fcb0 100644 --- a/pkg/compiler/compiler_like_test.go +++ b/pkg/compiler/compiler_like_test.go @@ -2,9 +2,11 @@ package compiler_test import ( "context" - "github.com/MontFerret/ferret/pkg/compiler" - . "github.com/smartystreets/goconvey/convey" "testing" + + . "github.com/smartystreets/goconvey/convey" + + "github.com/MontFerret/ferret/pkg/compiler" ) func TestLikeOperator(t *testing.T) { diff --git a/pkg/compiler/compiler_limit_test.go b/pkg/compiler/compiler_limit_test.go index 32b4dcff5..efe02e0a0 100644 --- a/pkg/compiler/compiler_limit_test.go +++ b/pkg/compiler/compiler_limit_test.go @@ -2,11 +2,13 @@ package compiler_test import ( "context" + "testing" + + . "github.com/smartystreets/goconvey/convey" + "github.com/MontFerret/ferret/pkg/compiler" "github.com/MontFerret/ferret/pkg/runtime/core" "github.com/MontFerret/ferret/pkg/runtime/values" - . "github.com/smartystreets/goconvey/convey" - "testing" ) func TestForLimit(t *testing.T) { diff --git a/pkg/compiler/compiler_logical_test.go b/pkg/compiler/compiler_logical_test.go index a777854d0..e86821fc4 100644 --- a/pkg/compiler/compiler_logical_test.go +++ b/pkg/compiler/compiler_logical_test.go @@ -3,11 +3,13 @@ package compiler_test import ( "context" "errors" + "testing" + + . "github.com/smartystreets/goconvey/convey" + "github.com/MontFerret/ferret/pkg/compiler" "github.com/MontFerret/ferret/pkg/runtime" "github.com/MontFerret/ferret/pkg/runtime/core" - . "github.com/smartystreets/goconvey/convey" - "testing" ) func TestLogicalOperators(t *testing.T) { diff --git a/pkg/compiler/compiler_math_test.go b/pkg/compiler/compiler_math_test.go index 0fc07f526..9d0397b67 100644 --- a/pkg/compiler/compiler_math_test.go +++ b/pkg/compiler/compiler_math_test.go @@ -2,10 +2,12 @@ package compiler_test import ( "context" + "testing" + + . "github.com/smartystreets/goconvey/convey" + "github.com/MontFerret/ferret/pkg/compiler" "github.com/MontFerret/ferret/pkg/runtime" - . "github.com/smartystreets/goconvey/convey" - "testing" ) func TestMathOperators(t *testing.T) { diff --git a/pkg/compiler/compiler_member_test.go b/pkg/compiler/compiler_member_test.go index 6f86bc018..fa2ffaf02 100644 --- a/pkg/compiler/compiler_member_test.go +++ b/pkg/compiler/compiler_member_test.go @@ -3,15 +3,17 @@ package compiler_test import ( "context" "fmt" - "github.com/MontFerret/ferret/pkg/parser" - "github.com/MontFerret/ferret/pkg/runtime/core" "regexp" "strconv" "strings" "testing" - "github.com/MontFerret/ferret/pkg/compiler" + "github.com/MontFerret/ferret/pkg/parser" + "github.com/MontFerret/ferret/pkg/runtime/core" + . "github.com/smartystreets/goconvey/convey" + + "github.com/MontFerret/ferret/pkg/compiler" ) func TestMember(t *testing.T) { @@ -525,7 +527,7 @@ RETURN o1.first["second"][o2.prop].fourth["fifth"]["bottom"] Convey("Reserved words as property name", t, func() { p := parser.New("RETURN TRUE") - r := regexp.MustCompile("\\w+") + r := regexp.MustCompile(`\w+`) for idx, l := range p.GetLiteralNames() { if r.MatchString(l) { diff --git a/pkg/compiler/compiler_param_test.go b/pkg/compiler/compiler_param_test.go index 8939a515f..59eced1dc 100644 --- a/pkg/compiler/compiler_param_test.go +++ b/pkg/compiler/compiler_param_test.go @@ -2,10 +2,12 @@ package compiler_test import ( "context" + "testing" + + . "github.com/smartystreets/goconvey/convey" + "github.com/MontFerret/ferret/pkg/compiler" "github.com/MontFerret/ferret/pkg/runtime" - . "github.com/smartystreets/goconvey/convey" - "testing" ) func TestParam(t *testing.T) { diff --git a/pkg/compiler/compiler_precedence_test.go b/pkg/compiler/compiler_precedence_test.go index 5306be3f1..21fc8640c 100644 --- a/pkg/compiler/compiler_precedence_test.go +++ b/pkg/compiler/compiler_precedence_test.go @@ -2,9 +2,10 @@ package compiler_test import ( "context" - "github.com/MontFerret/ferret/pkg/compiler" "testing" + "github.com/MontFerret/ferret/pkg/compiler" + . "github.com/smartystreets/goconvey/convey" ) diff --git a/pkg/compiler/compiler_range_test.go b/pkg/compiler/compiler_range_test.go index 70779d857..4b8adad83 100644 --- a/pkg/compiler/compiler_range_test.go +++ b/pkg/compiler/compiler_range_test.go @@ -2,9 +2,11 @@ package compiler_test import ( "context" - "github.com/MontFerret/ferret/pkg/compiler" - . "github.com/smartystreets/goconvey/convey" "testing" + + . "github.com/smartystreets/goconvey/convey" + + "github.com/MontFerret/ferret/pkg/compiler" ) func TestRangeOperator(t *testing.T) { diff --git a/pkg/compiler/compiler_regexp_test.go b/pkg/compiler/compiler_regexp_test.go index 7f85253aa..a1af1b5ba 100644 --- a/pkg/compiler/compiler_regexp_test.go +++ b/pkg/compiler/compiler_regexp_test.go @@ -3,12 +3,14 @@ package compiler_test import ( "context" "fmt" + "testing" + "github.com/MontFerret/ferret/pkg/runtime/core" "github.com/MontFerret/ferret/pkg/runtime/values" - "testing" - "github.com/MontFerret/ferret/pkg/compiler" . "github.com/smartystreets/goconvey/convey" + + "github.com/MontFerret/ferret/pkg/compiler" ) func TestRegexpOperator(t *testing.T) { diff --git a/pkg/compiler/compiler_return_test.go b/pkg/compiler/compiler_return_test.go index db067d3ba..e44239774 100644 --- a/pkg/compiler/compiler_return_test.go +++ b/pkg/compiler/compiler_return_test.go @@ -2,10 +2,12 @@ package compiler_test import ( "context" + "testing" + + . "github.com/smartystreets/goconvey/convey" + "github.com/MontFerret/ferret/pkg/compiler" "github.com/MontFerret/ferret/pkg/runtime" - . "github.com/smartystreets/goconvey/convey" - "testing" ) func TestReturn(t *testing.T) { diff --git a/pkg/compiler/compiler_sort_test.go b/pkg/compiler/compiler_sort_test.go index eeb45caa0..e11350cda 100644 --- a/pkg/compiler/compiler_sort_test.go +++ b/pkg/compiler/compiler_sort_test.go @@ -2,11 +2,13 @@ package compiler_test import ( "context" + "testing" + + . "github.com/smartystreets/goconvey/convey" + "github.com/MontFerret/ferret/pkg/compiler" "github.com/MontFerret/ferret/pkg/runtime/core" "github.com/MontFerret/ferret/pkg/runtime/values" - . "github.com/smartystreets/goconvey/convey" - "testing" ) func TestForSort(t *testing.T) { diff --git a/pkg/compiler/compiler_str_test.go b/pkg/compiler/compiler_str_test.go index 54a72df69..e4144cdff 100644 --- a/pkg/compiler/compiler_str_test.go +++ b/pkg/compiler/compiler_str_test.go @@ -4,9 +4,11 @@ import ( "context" "encoding/json" "fmt" - "github.com/MontFerret/ferret/pkg/compiler" - . "github.com/smartystreets/goconvey/convey" "testing" + + . "github.com/smartystreets/goconvey/convey" + + "github.com/MontFerret/ferret/pkg/compiler" ) func TestString(t *testing.T) { diff --git a/pkg/compiler/compiler_ternary_test.go b/pkg/compiler/compiler_ternary_test.go index 9eb3dd8f4..e2de74e44 100644 --- a/pkg/compiler/compiler_ternary_test.go +++ b/pkg/compiler/compiler_ternary_test.go @@ -3,9 +3,11 @@ package compiler_test import ( "context" "fmt" - "github.com/MontFerret/ferret/pkg/compiler" - . "github.com/smartystreets/goconvey/convey" "testing" + + . "github.com/smartystreets/goconvey/convey" + + "github.com/MontFerret/ferret/pkg/compiler" ) func TestTernaryOperator(t *testing.T) { diff --git a/pkg/compiler/compiler_unary_test.go b/pkg/compiler/compiler_unary_test.go index 25a291028..eb2a8226e 100644 --- a/pkg/compiler/compiler_unary_test.go +++ b/pkg/compiler/compiler_unary_test.go @@ -2,9 +2,11 @@ package compiler_test import ( "context" - "github.com/MontFerret/ferret/pkg/compiler" - . "github.com/smartystreets/goconvey/convey" "testing" + + . "github.com/smartystreets/goconvey/convey" + + "github.com/MontFerret/ferret/pkg/compiler" ) func TestUnaryOperator(t *testing.T) { diff --git a/pkg/compiler/compiler_use_test.go b/pkg/compiler/compiler_use_test.go index 5b7a7183b..39fc9d378 100644 --- a/pkg/compiler/compiler_use_test.go +++ b/pkg/compiler/compiler_use_test.go @@ -4,11 +4,12 @@ import ( "context" "testing" + . "github.com/smartystreets/goconvey/convey" + "github.com/MontFerret/ferret/pkg/compiler" "github.com/MontFerret/ferret/pkg/runtime/core" "github.com/MontFerret/ferret/pkg/stdlib/strings" "github.com/MontFerret/ferret/pkg/stdlib/types" - . "github.com/smartystreets/goconvey/convey" ) func TestUseExpression(t *testing.T) { diff --git a/pkg/compiler/compiler_waitfor_event_ternary_test.go b/pkg/compiler/compiler_waitfor_event_ternary_test.go index c08a59eb6..b10476678 100644 --- a/pkg/compiler/compiler_waitfor_event_ternary_test.go +++ b/pkg/compiler/compiler_waitfor_event_ternary_test.go @@ -2,8 +2,9 @@ package compiler_test import ( "context" - . "github.com/smartystreets/goconvey/convey" "testing" + + . "github.com/smartystreets/goconvey/convey" ) func TestWaitforEventWithinTernaryExpression(t *testing.T) { diff --git a/pkg/compiler/compiler_waitfor_event_test.go b/pkg/compiler/compiler_waitfor_event_test.go index e7ebab855..0065e9331 100644 --- a/pkg/compiler/compiler_waitfor_event_test.go +++ b/pkg/compiler/compiler_waitfor_event_test.go @@ -2,16 +2,18 @@ package compiler_test import ( "context" + "testing" + "time" + + "github.com/pkg/errors" + . "github.com/smartystreets/goconvey/convey" + "github.com/MontFerret/ferret/pkg/compiler" "github.com/MontFerret/ferret/pkg/runtime" "github.com/MontFerret/ferret/pkg/runtime/core" "github.com/MontFerret/ferret/pkg/runtime/events" "github.com/MontFerret/ferret/pkg/runtime/values" "github.com/MontFerret/ferret/pkg/runtime/values/types" - "github.com/pkg/errors" - . "github.com/smartystreets/goconvey/convey" - "testing" - "time" ) type ( diff --git a/pkg/compiler/listener.go b/pkg/compiler/listener.go index ab8c50c44..f473ab8fe 100644 --- a/pkg/compiler/listener.go +++ b/pkg/compiler/listener.go @@ -1,7 +1,7 @@ package compiler import ( - "github.com/antlr/antlr4/runtime/Go/antlr" + "github.com/antlr/antlr4/runtime/Go/antlr/v4" "github.com/pkg/errors" ) diff --git a/pkg/compiler/namespace.go b/pkg/compiler/namespace.go index f2beb1096..9cc12711f 100644 --- a/pkg/compiler/namespace.go +++ b/pkg/compiler/namespace.go @@ -4,8 +4,9 @@ import ( "regexp" "strings" - "github.com/MontFerret/ferret/pkg/runtime/core" "github.com/pkg/errors" + + "github.com/MontFerret/ferret/pkg/runtime/core" ) var fnNameValidation = regexp.MustCompile("^[a-zA-Z]+[a-zA-Z0-9_]*(::[a-zA-Z]+[a-zA-Z0-9_]*)*$") @@ -90,9 +91,7 @@ func (nc *NamespaceContainer) RegisteredFunctions() []string { // root namespace, return all functions if nc.name == emptyNS { - for _, k := range fnames { - res = append(res, k) - } + res = append(res, fnames...) } else { nsPrefix := nc.name + separator for _, k := range fnames { diff --git a/pkg/compiler/namespace_test.go b/pkg/compiler/namespace_test.go index e1375089e..92895eb80 100644 --- a/pkg/compiler/namespace_test.go +++ b/pkg/compiler/namespace_test.go @@ -2,11 +2,13 @@ package compiler_test import ( "context" + "testing" + + . "github.com/smartystreets/goconvey/convey" + "github.com/MontFerret/ferret/pkg/compiler" "github.com/MontFerret/ferret/pkg/runtime/core" "github.com/MontFerret/ferret/pkg/runtime/values" - . "github.com/smartystreets/goconvey/convey" - "testing" ) func TestNamespaceBuilder(t *testing.T) { diff --git a/pkg/compiler/visitor.go b/pkg/compiler/visitor.go index c71bf6425..d620af953 100644 --- a/pkg/compiler/visitor.go +++ b/pkg/compiler/visitor.go @@ -6,7 +6,7 @@ import ( "strconv" "strings" - "github.com/antlr/antlr4/runtime/Go/antlr" + "github.com/antlr/antlr4/runtime/Go/antlr/v4" "github.com/pkg/errors" "github.com/MontFerret/ferret/pkg/parser/fql" @@ -56,7 +56,8 @@ func (v *visitor) VisitProgram(ctx *fql.ProgramContext) interface{} { gs := newGlobalScope() rs := newRootScope(gs) - block, err := v.visitBody(ctx.Body().(fql.IBodyContext), rs) + block, err := v.visitBody(ctx.Body(), rs) + if err != nil { return nil, err } @@ -69,7 +70,7 @@ func (v *visitor) visitHeads(heads []fql.IHeadContext) error { namespaces := map[string]struct{}{} for _, head := range heads { - err := v.visitHead(head.(fql.IHeadContext), namespaces) + err := v.visitHead(head, namespaces) if err != nil { return err } @@ -142,7 +143,7 @@ func (v *visitor) visitBody(c fql.IBodyContext, scope *scope) (core.Expression, body := expressions.NewBodyExpression(len(statements) + 1) for _, stmt := range statements { - e, err := v.visitBodyStatement(stmt.(fql.IBodyStatementContext), scope) + e, err := v.visitBodyStatement(stmt, scope) if err != nil { return nil, err } @@ -153,7 +154,7 @@ func (v *visitor) visitBody(c fql.IBodyContext, scope *scope) (core.Expression, exp := ctx.BodyExpression() if exp != nil { - e, err := v.visitBodyExpression(exp.(fql.IBodyExpressionContext), scope) + e, err := v.visitBodyExpression(exp, scope) if err != nil { return nil, err } @@ -170,15 +171,15 @@ func (v *visitor) visitBodyStatement(c fql.IBodyStatementContext, scope *scope) ctx := c.(*fql.BodyStatementContext) if variable := ctx.VariableDeclaration(); variable != nil { - return v.visitVariableDeclaration(variable.(fql.IVariableDeclarationContext), scope) + return v.visitVariableDeclaration(variable, scope) } if funcCall := ctx.FunctionCallExpression(); funcCall != nil { - return v.visitFunctionCallExpression(funcCall.(fql.IFunctionCallExpressionContext), scope) + return v.visitFunctionCallExpression(funcCall, scope) } if waitfor := ctx.WaitForExpression(); waitfor != nil { - return v.visitWaitForExpression(waitfor.(fql.IWaitForExpressionContext), scope) + return v.visitWaitForExpression(waitfor, scope) } return nil, v.unexpectedToken(ctx) @@ -188,11 +189,11 @@ func (v *visitor) visitBodyExpression(c fql.IBodyExpressionContext, scope *scope ctx := c.(*fql.BodyExpressionContext) if exp := ctx.ForExpression(); exp != nil { - return v.visitForExpression(exp.(fql.IForExpressionContext), scope) + return v.visitForExpression(exp, scope) } if exp := ctx.ReturnExpression(); exp != nil { - return v.visitReturnExpression(exp.(fql.IReturnExpressionContext), scope) + return v.visitReturnExpression(exp, scope) } return nil, v.unexpectedToken(ctx) @@ -204,7 +205,7 @@ func (v *visitor) visitReturnExpression(c fql.IReturnExpressionContext, scope *s ctx := c.(*fql.ReturnExpressionContext) if exp := ctx.Expression(); exp != nil { - out, err = v.visitExpression(exp.(fql.IExpressionContext), scope) + out, err = v.visitExpression(exp, scope) } else { return nil, v.unexpectedToken(ctx) } @@ -254,7 +255,7 @@ func (v *visitor) visitForExpression(c fql.IForExpressionContext, scope *scope) return nil, err } } else { - whileExpCtx := ctx.Expression().(fql.IExpressionContext) + whileExpCtx := ctx.Expression() conditionExp, err := v.visitExpression(whileExpCtx, scope) if err != nil { @@ -301,7 +302,7 @@ func (v *visitor) visitForExpression(c fql.IForExpressionContext, scope *scope) if clauseCtx != nil { setter, err := v.visitForExpressionClause( - clauseCtx.(fql.IForExpressionClauseContext), + clauseCtx, forInScope, valVarName, keyVarName, @@ -314,7 +315,7 @@ func (v *visitor) visitForExpression(c fql.IForExpressionContext, scope *scope) parsedClauses = append(parsedClauses, setter) } else if statementCtx != nil { exp, err := v.visitForExpressionStatement( - statementCtx.(fql.IForExpressionStatementContext), + statementCtx, forInScope, ) @@ -396,19 +397,19 @@ func (v *visitor) visitLimitClause(c fql.ILimitClauseContext, scope *scope) (cor clauseValues := ctx.AllLimitClauseValue() if len(clauseValues) > 1 { - offset, err = v.visitLimitClauseValue(clauseValues[0].(fql.ILimitClauseValueContext), scope) + offset, err = v.visitLimitClauseValue(clauseValues[0], scope) if err != nil { return nil, nil, err } - count, err = v.visitLimitClauseValue(clauseValues[1].(fql.ILimitClauseValueContext), scope) + count, err = v.visitLimitClauseValue(clauseValues[1], scope) if err != nil { return nil, nil, err } } else { - count, err = v.visitLimitClauseValue(clauseValues[0].(fql.ILimitClauseValueContext), scope) + count, err = v.visitLimitClauseValue(clauseValues[0], scope) if err != nil { return nil, nil, err @@ -431,7 +432,7 @@ func (v *visitor) visitLimitClauseValue(c fql.ILimitClauseValueContext, scope *s return literals.NewIntLiteral(i), nil } else if paramCtx := ctx.Param(); paramCtx != nil { - return v.visitParam(paramCtx.(fql.IParamContext), scope) + return v.visitParam(paramCtx, scope) } else if variableCtx := ctx.Variable(); variableCtx != nil { return v.visitVariable(variableCtx, scope) } else if funcCtx := ctx.FunctionCallExpression(); funcCtx != nil { @@ -455,7 +456,7 @@ func (v *visitor) visitSortClause(c fql.ISortClauseContext, scope *scope) ([]*cl for idx, sortExpCtx := range sortExpCtxs { sortExpCtx := sortExpCtx.(*fql.SortClauseExpressionContext) - exp, err := v.visitExpression(sortExpCtx.Expression().(fql.IExpressionContext), scope) + exp, err := v.visitExpression(sortExpCtx.Expression(), scope) if err != nil { return nil, err } @@ -501,7 +502,7 @@ func (v *visitor) visitCollectClause(c fql.ICollectClauseContext, scope *scope, selectors = make([]*clauses.CollectSelector, 0, len(collectSelectors)) for _, cs := range collectSelectors { - selector, err := v.visitCollectSelector(cs.(fql.ICollectSelectorContext), scope) + selector, err := v.visitCollectSelector(cs, scope) if err != nil { return nil, err } @@ -520,7 +521,7 @@ func (v *visitor) visitCollectClause(c fql.ICollectClauseContext, scope *scope, // if projection expression is defined like WITH group = { foo: i.bar } if projectionSelectorCtx != nil { - selector, err := v.visitCollectSelector(projectionSelectorCtx.(fql.ICollectSelectorContext), scope) + selector, err := v.visitCollectSelector(projectionSelectorCtx, scope) if err != nil { return nil, err } @@ -592,7 +593,7 @@ func (v *visitor) visitCollectClause(c fql.ICollectClauseContext, scope *scope, selectors := make([]*clauses.CollectAggregateSelector, 0, len(selectorCtxs)) for _, sc := range selectorCtxs { - selector, err := v.visitCollectAggregateSelector(sc.(fql.ICollectAggregateSelectorContext), scope) + selector, err := v.visitCollectAggregateSelector(sc, scope) if err != nil { return nil, err } @@ -623,7 +624,7 @@ func (v *visitor) visitCollectClause(c fql.ICollectClauseContext, scope *scope, func (v *visitor) visitCollectSelector(c fql.ICollectSelectorContext, scope *scope) (*clauses.CollectSelector, error) { ctx := c.(*fql.CollectSelectorContext) variable := ctx.Identifier().GetText() - exp, err := v.visitExpression(ctx.Expression().(fql.IExpressionContext), scope) + exp, err := v.visitExpression(ctx.Expression(), scope) if err != nil { return nil, err @@ -638,7 +639,7 @@ func (v *visitor) visitCollectAggregateSelector(c fql.ICollectAggregateSelectorC fnCtx := ctx.FunctionCallExpression() if fnCtx != nil { - exp, err := v.visitFunctionCallExpression(fnCtx.(fql.IFunctionCallExpressionContext), scope) + exp, err := v.visitFunctionCallExpression(fnCtx, scope) if err != nil { return nil, err @@ -662,43 +663,43 @@ func (v *visitor) visitForExpressionSource(c fql.IForExpressionSourceContext, sc arr := ctx.ArrayLiteral() if arr != nil { - return v.visitArrayLiteral(arr.(fql.IArrayLiteralContext), scope) + return v.visitArrayLiteral(arr, scope) } obj := ctx.ObjectLiteral() if obj != nil { - return v.visitObjectLiteral(obj.(fql.IObjectLiteralContext), scope) + return v.visitObjectLiteral(obj, scope) } variable := ctx.Variable() if variable != nil { - return v.visitVariable(variable.(fql.IVariableContext), scope) + return v.visitVariable(variable, scope) } funcCall := ctx.FunctionCallExpression() if funcCall != nil { - return v.visitFunctionCallExpression(funcCall.(fql.IFunctionCallExpressionContext), scope) + return v.visitFunctionCallExpression(funcCall, scope) } memberExp := ctx.MemberExpression() if memberExp != nil { - return v.visitMemberExpression(memberExp.(fql.IMemberExpressionContext), scope) + return v.visitMemberExpression(memberExp, scope) } rangeOp := ctx.RangeOperator() if rangeOp != nil { - return v.visitRangeOperator(rangeOp.(fql.IRangeOperatorContext), scope) + return v.visitRangeOperator(rangeOp, scope) } param := ctx.Param() if param != nil { - return v.visitParam(param.(fql.IParamContext), scope) + return v.visitParam(param, scope) } return nil, core.Error(ErrInvalidDataSource, ctx.GetText()) @@ -710,7 +711,7 @@ func (v *visitor) visitForExpressionClause(c fql.IForExpressionClauseContext, sc limitCtx := ctx.LimitClause() if limitCtx != nil { - limit, offset, err := v.visitLimitClause(limitCtx.(fql.ILimitClauseContext), scope) + limit, offset, err := v.visitLimitClause(limitCtx, scope) if err != nil { return nil, err } @@ -723,7 +724,7 @@ func (v *visitor) visitForExpressionClause(c fql.IForExpressionClauseContext, sc filterCtx := ctx.FilterClause() if filterCtx != nil { - filterExp, err := v.visitFilterClause(filterCtx.(fql.IFilterClauseContext), scope) + filterExp, err := v.visitFilterClause(filterCtx, scope) if err != nil { return nil, err } @@ -736,7 +737,6 @@ func (v *visitor) visitForExpressionClause(c fql.IForExpressionClauseContext, sc sortCtx := ctx.SortClause() if sortCtx != nil { - sortCtx := sortCtx.(fql.ISortClauseContext) sortExps, err := v.visitSortClause(sortCtx, scope) if err != nil { return nil, err @@ -750,7 +750,6 @@ func (v *visitor) visitForExpressionClause(c fql.IForExpressionClauseContext, sc collectCtx := ctx.CollectClause() if collectCtx != nil { - collectCtx := collectCtx.(fql.ICollectClauseContext) params, err := v.visitCollectClause(collectCtx, scope, valVarName) if err != nil { return nil, err @@ -771,7 +770,7 @@ func (v *visitor) visitForExpressionStatement(c fql.IForExpressionStatementConte if variableCtx != nil { variableExp, err := v.visitVariableDeclaration( - variableCtx.(fql.IVariableDeclarationContext), + variableCtx, scope, ) if err != nil { @@ -787,7 +786,7 @@ func (v *visitor) visitForExpressionStatement(c fql.IForExpressionStatementConte if fnCallCtx != nil { fnCallExp, err := v.visitFunctionCallExpression( - fnCallCtx.(fql.IFunctionCallExpressionContext), + fnCallCtx, scope, ) if err != nil { @@ -1108,7 +1107,7 @@ func (v *visitor) visitPropertyName(c fql.IPropertyNameContext, scope *scope) (c return literals.NewStringLiteral(rw.GetText()), nil } - if rw := ctx.UnsafReservedWord(); rw != nil { + if rw := ctx.UnsafeReservedWord(); rw != nil { return literals.NewStringLiteral(rw.GetText()), nil } @@ -1136,7 +1135,7 @@ func (v *visitor) visitArrayLiteral(c fql.IArrayLiteralContext, scope *scope) (c list := ctx.ArgumentList() if list == nil { - return literals.NewArrayLiteralWith(make([]core.Expression, 0, 0)), nil + return literals.NewArrayLiteralWith(make([]core.Expression, 0)), nil } elements, err := v.visitArgumentList(list, scope) @@ -1258,7 +1257,7 @@ func (v *visitor) visitVariableDeclaration(c fql.IVariableDeclarationContext, sc } if exp := ctx.Expression(); exp != nil { - init, err = v.visitExpression(ctx.Expression().(fql.IExpressionContext), scope) + init, err = v.visitExpression(ctx.Expression(), scope) } if err != nil { @@ -1373,7 +1372,7 @@ func (v *visitor) visitArgumentList(c fql.IArgumentListContext, scope *scope) ([ args := make([]core.Expression, 0, len(exps)) for _, arg := range exps { - exp, err := v.visitExpression(arg.(fql.IExpressionContext), scope) + exp, err := v.visitExpression(arg, scope) if err != nil { return nil, err @@ -1454,7 +1453,7 @@ func (v *visitor) visitExpression(c fql.IExpressionContext, scope *scope) (core. } if ctx.GetTernaryOperator() != nil { - cond, err := v.visitExpression(ctx.GetCondition().(fql.IExpressionContext), scope) + cond, err := v.visitExpression(ctx.GetCondition(), scope) if err != nil { return nil, err @@ -1463,7 +1462,7 @@ func (v *visitor) visitExpression(c fql.IExpressionContext, scope *scope) (core. var consequent core.Expression if onTrue := ctx.GetOnTrue(); onTrue != nil { - exp, err := v.visitExpression(onTrue.(fql.IExpressionContext), scope) + exp, err := v.visitExpression(onTrue, scope) if err != nil { return nil, err @@ -1472,7 +1471,7 @@ func (v *visitor) visitExpression(c fql.IExpressionContext, scope *scope) (core. consequent = exp } - alternate, err := v.visitExpression(ctx.GetOnFalse().(fql.IExpressionContext), scope) + alternate, err := v.visitExpression(ctx.GetOnFalse(), scope) if err != nil { return nil, err diff --git a/pkg/drivers/cdp/dom/loader.go b/pkg/drivers/cdp/dom/loader.go index 5d9ccc748..3586cc383 100644 --- a/pkg/drivers/cdp/dom/loader.go +++ b/pkg/drivers/cdp/dom/loader.go @@ -3,10 +3,11 @@ package dom import ( "context" - "github.com/MontFerret/ferret/pkg/drivers/cdp/eval" - "github.com/MontFerret/ferret/pkg/runtime/core" "github.com/mafredri/cdp/protocol/page" "github.com/mafredri/cdp/protocol/runtime" + + "github.com/MontFerret/ferret/pkg/drivers/cdp/eval" + "github.com/MontFerret/ferret/pkg/runtime/core" ) type NodeLoader struct { diff --git a/pkg/drivers/cdp/eval/function.go b/pkg/drivers/cdp/eval/function.go index c7d2734a6..702ac7b9c 100644 --- a/pkg/drivers/cdp/eval/function.go +++ b/pkg/drivers/cdp/eval/function.go @@ -1,12 +1,14 @@ package eval import ( - "github.com/MontFerret/ferret/pkg/drivers" - "github.com/MontFerret/ferret/pkg/runtime/core" - "github.com/mafredri/cdp/protocol/runtime" - "github.com/wI2L/jettison" "strconv" "strings" + + "github.com/mafredri/cdp/protocol/runtime" + "github.com/wI2L/jettison" + + "github.com/MontFerret/ferret/pkg/drivers" + "github.com/MontFerret/ferret/pkg/runtime/core" ) type Function struct { diff --git a/pkg/drivers/cdp/eval/runtime.go b/pkg/drivers/cdp/eval/runtime.go index cfeb11631..844be8842 100644 --- a/pkg/drivers/cdp/eval/runtime.go +++ b/pkg/drivers/cdp/eval/runtime.go @@ -98,13 +98,17 @@ func (rt *Runtime) EvalValue(ctx context.Context, fn *Function) (core.Value, err return rt.resolver.ToValue(ctx, out) } -func (rt *Runtime) EvalElement(ctx context.Context, fn *Function) (drivers.HTMLElement, error) { +func (rt *Runtime) EvalElement(ctx context.Context, fn *Function) (core.Value, error) { ref, err := rt.EvalRef(ctx, fn) if err != nil { return nil, err } + if ref.ObjectID == nil { + return values.None, nil + } + return rt.resolver.ToElement(ctx, ref) } diff --git a/pkg/drivers/cdp/events/loop_test.go b/pkg/drivers/cdp/events/loop_test.go index 92427ea5c..2e0704de9 100644 --- a/pkg/drivers/cdp/events/loop_test.go +++ b/pkg/drivers/cdp/events/loop_test.go @@ -2,13 +2,15 @@ package events_test import ( "context" - "github.com/MontFerret/ferret/pkg/drivers/cdp/events" - "github.com/mafredri/cdp/rpcc" - . "github.com/smartystreets/goconvey/convey" "sync" "sync/atomic" "testing" "time" + + "github.com/mafredri/cdp/rpcc" + . "github.com/smartystreets/goconvey/convey" + + "github.com/MontFerret/ferret/pkg/drivers/cdp/events" ) type TestEventStream struct { diff --git a/pkg/drivers/cdp/events/source.go b/pkg/drivers/cdp/events/source.go index 0ac8e4b4e..4e32d3384 100644 --- a/pkg/drivers/cdp/events/source.go +++ b/pkg/drivers/cdp/events/source.go @@ -2,6 +2,7 @@ package events import ( "context" + "github.com/mafredri/cdp/rpcc" ) diff --git a/pkg/drivers/cdp/events/stream.go b/pkg/drivers/cdp/events/stream.go index a4d45f958..a1caceafe 100644 --- a/pkg/drivers/cdp/events/stream.go +++ b/pkg/drivers/cdp/events/stream.go @@ -2,10 +2,12 @@ package events import ( "context" + + "github.com/mafredri/cdp/rpcc" + "github.com/MontFerret/ferret/pkg/runtime/core" "github.com/MontFerret/ferret/pkg/runtime/events" "github.com/MontFerret/ferret/pkg/runtime/values" - "github.com/mafredri/cdp/rpcc" ) type ( diff --git a/pkg/drivers/cdp/events/stream_test.go b/pkg/drivers/cdp/events/stream_test.go index ca9348a72..5bc619c17 100644 --- a/pkg/drivers/cdp/events/stream_test.go +++ b/pkg/drivers/cdp/events/stream_test.go @@ -2,15 +2,17 @@ package events_test import ( "context" + "testing" + "time" + + "github.com/mafredri/cdp/rpcc" + "github.com/pkg/errors" + "github.com/stretchr/testify/mock" + events2 "github.com/MontFerret/ferret/pkg/drivers/cdp/events" "github.com/MontFerret/ferret/pkg/runtime/core" "github.com/MontFerret/ferret/pkg/runtime/events" "github.com/MontFerret/ferret/pkg/runtime/values" - "github.com/mafredri/cdp/rpcc" - "github.com/pkg/errors" - "github.com/stretchr/testify/mock" - "testing" - "time" . "github.com/smartystreets/goconvey/convey" ) diff --git a/pkg/drivers/cdp/helpers.go b/pkg/drivers/cdp/helpers.go index e67a8055d..0c0e323e8 100644 --- a/pkg/drivers/cdp/helpers.go +++ b/pkg/drivers/cdp/helpers.go @@ -2,10 +2,12 @@ package cdp import ( "context" + + "github.com/mafredri/cdp/protocol/dom" + "github.com/MontFerret/ferret/pkg/runtime/events" "github.com/mafredri/cdp" - "github.com/mafredri/cdp/protocol/dom" "github.com/mafredri/cdp/protocol/emulation" "github.com/mafredri/cdp/protocol/network" "github.com/mafredri/cdp/protocol/page" @@ -66,7 +68,7 @@ func enableFeatures(ctx context.Context, client *cdp.Client, params drivers.Para }, func() error { - return client.DOM.Enable(ctx, dom.NewEnableArgs()) + return client.DOM.Enable(ctx, dom.NewEnableArgs().SetIncludeWhitespace("all")) }, func() error { diff --git a/pkg/drivers/cdp/network/event.go b/pkg/drivers/cdp/network/event.go index ceb7f9bc3..9149bd4bf 100644 --- a/pkg/drivers/cdp/network/event.go +++ b/pkg/drivers/cdp/network/event.go @@ -2,10 +2,12 @@ package network import ( "context" - "github.com/MontFerret/ferret/pkg/drivers/cdp/dom" + "github.com/mafredri/cdp/protocol/page" "github.com/wI2L/jettison" + "github.com/MontFerret/ferret/pkg/drivers/cdp/dom" + "github.com/MontFerret/ferret/pkg/runtime/core" "github.com/MontFerret/ferret/pkg/runtime/values" ) diff --git a/pkg/drivers/cdp/templates/attributes.go b/pkg/drivers/cdp/templates/attributes.go index 6bb8eee33..24d9045ab 100644 --- a/pkg/drivers/cdp/templates/attributes.go +++ b/pkg/drivers/cdp/templates/attributes.go @@ -2,9 +2,11 @@ package templates import ( "fmt" + + "github.com/mafredri/cdp/protocol/runtime" + "github.com/MontFerret/ferret/pkg/drivers/cdp/eval" "github.com/MontFerret/ferret/pkg/runtime/values" - "github.com/mafredri/cdp/protocol/runtime" ) const getAttribute = `(el, name) => { diff --git a/pkg/drivers/cdp/templates/blur.go b/pkg/drivers/cdp/templates/blur.go index 07fe4a47a..1866c8012 100644 --- a/pkg/drivers/cdp/templates/blur.go +++ b/pkg/drivers/cdp/templates/blur.go @@ -3,9 +3,10 @@ package templates import ( "fmt" + "github.com/mafredri/cdp/protocol/runtime" + "github.com/MontFerret/ferret/pkg/drivers" "github.com/MontFerret/ferret/pkg/drivers/cdp/eval" - "github.com/mafredri/cdp/protocol/runtime" ) const blur = `(el) => { diff --git a/pkg/drivers/cdp/templates/children.go b/pkg/drivers/cdp/templates/children.go index 4b7a99b98..90d3db5fb 100644 --- a/pkg/drivers/cdp/templates/children.go +++ b/pkg/drivers/cdp/templates/children.go @@ -1,9 +1,10 @@ package templates import ( + "github.com/mafredri/cdp/protocol/runtime" + "github.com/MontFerret/ferret/pkg/drivers/cdp/eval" "github.com/MontFerret/ferret/pkg/runtime/values" - "github.com/mafredri/cdp/protocol/runtime" ) const getChildren = "(el) => Array.from(el.children)" diff --git a/pkg/drivers/cdp/templates/helpers.go b/pkg/drivers/cdp/templates/helpers.go index d1ef8284c..39f670ebe 100644 --- a/pkg/drivers/cdp/templates/helpers.go +++ b/pkg/drivers/cdp/templates/helpers.go @@ -2,6 +2,7 @@ package templates import ( "fmt" + "github.com/MontFerret/ferret/pkg/drivers" "github.com/MontFerret/ferret/pkg/drivers/cdp/eval" ) diff --git a/pkg/drivers/cdp/templates/inner_html.go b/pkg/drivers/cdp/templates/inner_html.go index f7586682e..ecdf216d7 100644 --- a/pkg/drivers/cdp/templates/inner_html.go +++ b/pkg/drivers/cdp/templates/inner_html.go @@ -2,10 +2,12 @@ package templates import ( "fmt" + + "github.com/mafredri/cdp/protocol/runtime" + "github.com/MontFerret/ferret/pkg/drivers" "github.com/MontFerret/ferret/pkg/drivers/cdp/eval" "github.com/MontFerret/ferret/pkg/runtime/values" - "github.com/mafredri/cdp/protocol/runtime" ) const setInnerHTML = `(el, value) => { diff --git a/pkg/drivers/cdp/templates/inner_text.go b/pkg/drivers/cdp/templates/inner_text.go index 09a800529..85ac77734 100644 --- a/pkg/drivers/cdp/templates/inner_text.go +++ b/pkg/drivers/cdp/templates/inner_text.go @@ -2,10 +2,12 @@ package templates import ( "fmt" + + "github.com/mafredri/cdp/protocol/runtime" + "github.com/MontFerret/ferret/pkg/drivers" "github.com/MontFerret/ferret/pkg/drivers/cdp/eval" "github.com/MontFerret/ferret/pkg/runtime/values" - "github.com/mafredri/cdp/protocol/runtime" ) const setInnerText = `(el, value) => { diff --git a/pkg/drivers/cdp/templates/parent.go b/pkg/drivers/cdp/templates/parent.go index 826263d72..3b43e6752 100644 --- a/pkg/drivers/cdp/templates/parent.go +++ b/pkg/drivers/cdp/templates/parent.go @@ -1,8 +1,9 @@ package templates import ( - "github.com/MontFerret/ferret/pkg/drivers/cdp/eval" "github.com/mafredri/cdp/protocol/runtime" + + "github.com/MontFerret/ferret/pkg/drivers/cdp/eval" ) const getParent = "(el) => el.parentElement" diff --git a/pkg/drivers/cdp/templates/query.go b/pkg/drivers/cdp/templates/query.go index 382f4413e..678dc29ca 100644 --- a/pkg/drivers/cdp/templates/query.go +++ b/pkg/drivers/cdp/templates/query.go @@ -2,9 +2,11 @@ package templates import ( "fmt" + + "github.com/mafredri/cdp/protocol/runtime" + "github.com/MontFerret/ferret/pkg/drivers" "github.com/MontFerret/ferret/pkg/drivers/cdp/eval" - "github.com/mafredri/cdp/protocol/runtime" ) const ( @@ -14,27 +16,21 @@ const ( ) var ( - queryCSSSelector = fmt.Sprintf(` + queryCSSSelector = ` (el, selector) => { const found = el.querySelector(selector); - %s - return found; } - `, - notFoundErrorFragment, - ) + ` queryXPathSelector = fmt.Sprintf(` (el, selector) => { %s - - %s return found; } `, - xpathAsElementFragment, notFoundErrorFragment, + xpathAsElementFragment, ) ) diff --git a/pkg/drivers/cdp/templates/select.go b/pkg/drivers/cdp/templates/select.go index 86a0db51f..9b5238a31 100644 --- a/pkg/drivers/cdp/templates/select.go +++ b/pkg/drivers/cdp/templates/select.go @@ -2,10 +2,12 @@ package templates import ( "fmt" + + "github.com/mafredri/cdp/protocol/runtime" + "github.com/MontFerret/ferret/pkg/drivers" "github.com/MontFerret/ferret/pkg/drivers/cdp/eval" "github.com/MontFerret/ferret/pkg/runtime/values" - "github.com/mafredri/cdp/protocol/runtime" ) const selectFragment = ` diff --git a/pkg/drivers/cdp/templates/siblings.go b/pkg/drivers/cdp/templates/siblings.go index 1c70c77fa..0b4ccb9b8 100644 --- a/pkg/drivers/cdp/templates/siblings.go +++ b/pkg/drivers/cdp/templates/siblings.go @@ -1,8 +1,9 @@ package templates import ( - "github.com/MontFerret/ferret/pkg/drivers/cdp/eval" "github.com/mafredri/cdp/protocol/runtime" + + "github.com/MontFerret/ferret/pkg/drivers/cdp/eval" ) const getPreviousElementSibling = "(el) => el.previousElementSibling" diff --git a/pkg/drivers/cdp/templates/styles.go b/pkg/drivers/cdp/templates/styles.go index cb68057b1..19ea0a76f 100644 --- a/pkg/drivers/cdp/templates/styles.go +++ b/pkg/drivers/cdp/templates/styles.go @@ -1,9 +1,10 @@ package templates import ( + "github.com/mafredri/cdp/protocol/runtime" + "github.com/MontFerret/ferret/pkg/drivers/cdp/eval" "github.com/MontFerret/ferret/pkg/runtime/values" - "github.com/mafredri/cdp/protocol/runtime" ) const getStyles = `(el) => { diff --git a/pkg/drivers/cdp/templates/value.go b/pkg/drivers/cdp/templates/value.go index 778e59631..6b2210901 100644 --- a/pkg/drivers/cdp/templates/value.go +++ b/pkg/drivers/cdp/templates/value.go @@ -1,9 +1,10 @@ package templates import ( + "github.com/mafredri/cdp/protocol/runtime" + "github.com/MontFerret/ferret/pkg/drivers/cdp/eval" "github.com/MontFerret/ferret/pkg/runtime/core" - "github.com/mafredri/cdp/protocol/runtime" ) const getValue = `(el) => { diff --git a/pkg/drivers/cdp/templates/wait.go b/pkg/drivers/cdp/templates/wait.go index 12b2d54c6..3fd828215 100644 --- a/pkg/drivers/cdp/templates/wait.go +++ b/pkg/drivers/cdp/templates/wait.go @@ -2,11 +2,13 @@ package templates import ( "fmt" + + "github.com/mafredri/cdp/protocol/runtime" + "github.com/MontFerret/ferret/pkg/drivers" "github.com/MontFerret/ferret/pkg/drivers/cdp/eval" "github.com/MontFerret/ferret/pkg/runtime/core" "github.com/MontFerret/ferret/pkg/runtime/values" - "github.com/mafredri/cdp/protocol/runtime" ) const ( diff --git a/pkg/drivers/cdp/templates/xpath.go b/pkg/drivers/cdp/templates/xpath.go index 3dd83446a..426e04b51 100644 --- a/pkg/drivers/cdp/templates/xpath.go +++ b/pkg/drivers/cdp/templates/xpath.go @@ -2,9 +2,11 @@ package templates import ( "fmt" + + "github.com/mafredri/cdp/protocol/runtime" + "github.com/MontFerret/ferret/pkg/drivers/cdp/eval" "github.com/MontFerret/ferret/pkg/runtime/values" - "github.com/mafredri/cdp/protocol/runtime" ) const xpath = `(el, expression, resType) => { diff --git a/pkg/drivers/common/errors.go b/pkg/drivers/common/errors.go index 2f3f94f1f..22af84b0c 100644 --- a/pkg/drivers/common/errors.go +++ b/pkg/drivers/common/errors.go @@ -3,8 +3,9 @@ package common import ( "io" - "github.com/MontFerret/ferret/pkg/runtime/core" "github.com/rs/zerolog" + + "github.com/MontFerret/ferret/pkg/runtime/core" ) var ( diff --git a/pkg/drivers/common/styles_test.go b/pkg/drivers/common/styles_test.go index a994ce0a0..df95c67d2 100644 --- a/pkg/drivers/common/styles_test.go +++ b/pkg/drivers/common/styles_test.go @@ -2,10 +2,11 @@ package common_test import ( "bytes" + "testing" + "github.com/MontFerret/ferret/pkg/drivers/common" "github.com/MontFerret/ferret/pkg/runtime/core" "github.com/MontFerret/ferret/pkg/runtime/values" - "testing" . "github.com/smartystreets/goconvey/convey" ) diff --git a/pkg/drivers/container.go b/pkg/drivers/container.go index 0d740569f..2a21a77db 100644 --- a/pkg/drivers/container.go +++ b/pkg/drivers/container.go @@ -2,6 +2,7 @@ package drivers import ( "context" + "github.com/MontFerret/ferret/pkg/runtime/core" ) diff --git a/pkg/drivers/cookie.go b/pkg/drivers/cookie.go index 9560aacbb..21989e03b 100644 --- a/pkg/drivers/cookie.go +++ b/pkg/drivers/cookie.go @@ -136,7 +136,8 @@ func (c HTTPCookie) Hash() uint64 { } func (c HTTPCookie) Copy() core.Value { - return *(&c) + cop := c + return &cop } func (c HTTPCookie) MarshalJSON() ([]byte, error) { diff --git a/pkg/drivers/headers.go b/pkg/drivers/headers.go index 2757dbca3..f3b13c7c8 100644 --- a/pkg/drivers/headers.go +++ b/pkg/drivers/headers.go @@ -9,9 +9,10 @@ import ( "sort" "strings" + "github.com/wI2L/jettison" + "github.com/MontFerret/ferret/pkg/runtime/core" "github.com/MontFerret/ferret/pkg/runtime/values" - "github.com/wI2L/jettison" ) // HTTPHeaders HTTP header object diff --git a/pkg/drivers/http/element.go b/pkg/drivers/http/element.go index c7a753276..a20a706dc 100644 --- a/pkg/drivers/http/element.go +++ b/pkg/drivers/http/element.go @@ -2,10 +2,11 @@ package http import ( "context" - "golang.org/x/net/html" "hash/fnv" "strings" + "golang.org/x/net/html" + "github.com/PuerkitoBio/goquery" "github.com/wI2L/jettison" diff --git a/pkg/drivers/http/element_test.go b/pkg/drivers/http/element_test.go index 4911cc3a2..35c98abe5 100644 --- a/pkg/drivers/http/element_test.go +++ b/pkg/drivers/http/element_test.go @@ -3,12 +3,15 @@ package http_test import ( "bytes" "context" + "testing" + + "github.com/PuerkitoBio/goquery" + . "github.com/smartystreets/goconvey/convey" + "github.com/MontFerret/ferret/pkg/drivers" "github.com/MontFerret/ferret/pkg/drivers/http" "github.com/MontFerret/ferret/pkg/runtime/values" - "github.com/PuerkitoBio/goquery" - . "github.com/smartystreets/goconvey/convey" - "testing" + "github.com/MontFerret/ferret/pkg/runtime/values/types" ) func TestElement(t *testing.T) { @@ -447,5 +450,55 @@ func TestElement(t *testing.T) { So(err, ShouldBeNil) So(nt.String(), ShouldEqual, "[\"Album example for Bootstrap\"]") }) + + Convey("Func", func() { + buff := bytes.NewBuffer([]byte(doc)) + + buff.Write([]byte(doc)) + + doc, err := goquery.NewDocumentFromReader(buff) + + So(err, ShouldBeNil) + + el, err := http.NewHTMLElement(doc.Find("html")) + + So(err, ShouldBeNil) + + nt, err := el.XPath(context.Background(), values.NewString("count(//div)")) + + So(err, ShouldBeNil) + So(nt.Type().String(), ShouldEqual, types.Float.String()) + }) + + Convey("Attributes", func() { + buff := bytes.NewBuffer([]byte(`