cloudflare/pint

Public

mirrored from https://github.com/cloudflare/pintAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.16.1

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

internal/parser/utils/binary_expr_test.go

61lines · modeblame

d292a71cLukasz Mierzwa4 years ago1package utils_test
2
3import (
4"testing"
5
1be963afLukasz Mierzwa4 years ago6"github.com/stretchr/testify/require"
d292a71cLukasz Mierzwa4 years ago7
8"github.com/cloudflare/pint/internal/parser"
9"github.com/cloudflare/pint/internal/parser/utils"
10)
11
12func TestHasOuterBinaryExpr(t *testing.T) {
13type testCaseT struct {
14expr string
15output string
16}
17
18testCases := []testCaseT{
19{
20expr: "foo",
21},
22{
23expr: "foo / bar",
24output: "foo / bar",
25},
26{
27expr: "(foo / bar)",
28output: "foo / bar",
29},
30{
31expr: "(foo / bar) / bob",
32output: "(foo / bar) / bob",
33},
34{
35expr: "foo / bar / bob",
36output: "foo / bar / bob",
37},
173eb627Lukasz Mierzwa4 years ago38{
39expr: "foo / bar > 0",
40output: "foo / bar > 0",
41},
d292a71cLukasz Mierzwa4 years ago42}
43
44for _, tc := range testCases {
45t.Run(tc.expr, func(t *testing.T) {
46n, err := parser.DecodeExpr(tc.expr)
47if err != nil {
48t.Error(err)
49t.FailNow()
50}
51bin := utils.HasOuterBinaryExpr(n)
52if bin == nil {
53if tc.output != "" {
54t.Errorf("HasOuterBinaryExpr() returned nil, expected %s", tc.output)
55}
56} else {
1be963afLukasz Mierzwa4 years ago57require.Equal(t, tc.output, bin.String(), "HasOuterBinaryExpr() returned wrong output")
d292a71cLukasz Mierzwa4 years ago58}
59})
60}
61}