github.com/rajeev159/opa@v0.45.0/ast/builtins_test.go (about) 1 // Copyright 2017 The OPA Authors. All rights reserved. 2 // Use of this source code is governed by an Apache2 3 // license that can be found in the LICENSE file. 4 5 package ast 6 7 import ( 8 "encoding/json" 9 "testing" 10 11 "github.com/open-policy-agent/opa/types" 12 ) 13 14 func TestBuiltinDeclRoundtrip(t *testing.T) { 15 16 bs, err := json.Marshal(Plus) 17 if err != nil { 18 t.Fatal(err) 19 } 20 21 var cpy Builtin 22 23 if err := json.Unmarshal(bs, &cpy); err != nil { 24 t.Fatal(err) 25 } 26 27 if types.Compare(cpy.Decl, Plus.Decl) != 0 || cpy.Name != Plus.Name || cpy.Infix != Plus.Infix || cpy.Relation != Plus.Relation { 28 t.Fatal("expected:", Plus, "got:", cpy) 29 } 30 }