package anchor import ( "reflect" "testing" ) func TestNew(t *testing.T) { type args struct { modifier AnchorType key string } tests := []struct { name string args args want Anchor }{{ args: args{Condition, ""}, want: nil, }, { args: args{Global, ""}, want: nil, }, { args: args{Negation, ""}, want: nil, }, { args: args{AddIfNotPresent, ""}, want: nil, }, { args: args{Equality, ""}, want: nil, }, { args: args{Existence, ""}, want: nil, }, { args: args{Condition, "test"}, want: anchor{Condition, "test"}, }, { args: args{Global, "test"}, want: anchor{Global, "test"}, }, { args: args{Negation, "test"}, want: anchor{Negation, "test"}, }, { args: args{AddIfNotPresent, "test"}, want: anchor{AddIfNotPresent, "test"}, }, { args: args{Equality, "test"}, want: anchor{Equality, "test"}, }, { args: args{Existence, "test"}, want: anchor{Existence, "test"}, }} for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := New(tt.args.modifier, tt.args.key); !reflect.DeepEqual(got, tt.want) { t.Errorf("New() = %v, want %v", got, tt.want) } }) } } func TestString(t *testing.T) { type args struct { modifier AnchorType key string } tests := []struct { name string args args want string }{{ args: args{Condition, ""}, want: "", }, { args: args{Global, ""}, want: "", }, { args: args{Negation, ""}, want: "", }, { args: args{AddIfNotPresent, ""}, want: "", }, { args: args{Equality, ""}, want: "", }, { args: args{Existence, ""}, want: "", }, { args: args{Condition, "test"}, want: "(test)", }, { args: args{Global, "test"}, want: "<(test)", }, { args: args{Negation, "test"}, want: "X(test)", }, { args: args{AddIfNotPresent, "test"}, want: "+(test)", }, { args: args{Equality, "test"}, want: "=(test)", }, { args: args{Existence, "test"}, want: "^(test)", }} for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := String(tt.args.modifier, tt.args.key); got != tt.want { t.Errorf("String() = %v, want %v", got, tt.want) } }) } } func TestIsOneOf(t *testing.T) { type args struct { a Anchor types []AnchorType } tests := []struct { name string args args want bool }{{ args: args{}, want: false, }, { args: args{nil, []AnchorType{Condition, Negation}}, want: false, }, { args: args{New(Condition, "test"), nil}, want: false, }, { args: args{New(Condition, "test"), []AnchorType{}}, want: false, }, { args: args{New(Condition, "test"), []AnchorType{Condition}}, want: true, }, { args: args{New(Condition, "test"), []AnchorType{Condition, Negation}}, want: true, }, { args: args{New(Condition, "test"), []AnchorType{Negation, Global}}, want: false, }} for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := IsOneOf(tt.args.a, tt.args.types...); got != tt.want { t.Errorf("IsOneOf() = %v, want %v", got, tt.want) } }) } } func TestParse(t *testing.T) { type args struct { str string } tests := []struct { name string args args want Anchor }{ { args: args{"(something)"}, want: anchor{Condition, "something"}, }, { args: args{"()"}, want: nil, }, { args: args{"something"}, want: nil, }, { args: args{"(something"}, want: nil, }, { args: args{"something)"}, want: nil, }, { args: args{"so)m(et(hin)g"}, want: nil, }, { args: args{""}, want: nil, }, { args: args{"^(abc)"}, want: anchor{Existence, "abc"}, }, { args: args{"^(abc"}, want: nil, }, { args: args{"^abc"}, want: nil, }, { args: args{"^()"}, want: nil, }, { args: args{"(abc)"}, want: anchor{Condition, "abc"}, }, { args: args{"=(abc)"}, want: anchor{Equality, "abc"}, }, { args: args{"=(abc"}, want: nil, }, { args: args{"=abc"}, want: nil, }, { args: args{"+(abc)"}, want: anchor{AddIfNotPresent, "abc"}, }, { args: args{"+(abc"}, want: nil, }, { args: args{"+abc"}, want: nil, }, { args: args{"X(abc)"}, want: anchor{Negation, "abc"}, }, { args: args{"X(abc"}, want: nil, }, { args: args{"Xabc"}, want: nil, }, { args: args{"<(abc)"}, want: anchor{Global, "abc"}, }, { args: args{"<(abc"}, want: nil, }, { args: args{"