1
0
Fork 0
Little S-Expression Framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sxpf/lookup_test.go

48 lines
1.4 KiB

//-----------------------------------------------------------------------------
// Copyright (c) 2022 Detlef Stern
//
// This file is part of sxpf.
//
// sxpf is licensed under the latest version of the EUPL // (European Union
// Public License). Please see file LICENSE.txt for your rights and obligations
// under this license.
//-----------------------------------------------------------------------------
package sxpf_test
import (
"testing"
"codeberg.org/t73fde/sxpf"
)
func TestSymbolMapSexpr(t *testing.T) {
smk := sxpf.NewTrivialSymbolMaker()
m := sxpf.NewSymbolMap(smk, nil)
sym := smk.MakeSymbol("map")
m.Set(sym, m) // A SymbolMap is itself a Sexpr
m1, found := m.Lookup(sym)
if !found {
t.Errorf("Symbol %v not found, but should be there", sym)
} else if !m.Equal(m1) {
t.Errorf("Expected map %v, but got: %v", m, m1)
}
}
func TestSymbolMapPrint(t *testing.T) {
smk := sxpf.NewTrivialSymbolMaker()
sm1 := sxpf.NewSymbolMap(smk, nil)
sm1.Set(smk.MakeSymbol("sym1"), sxpf.NewString("val1"))
got := sm1.String()
exp := `("symbol" ("parent" ()) (SYM1 "val1"))`
if exp != got {
t.Errorf("sm1:\nexpected: %v,\n but got: %v", exp, got)
}
sm2 := sxpf.NewSymbolMap(smk, sm1)
sm2.Set(smk.MakeSymbol("sym2"), sxpf.NewString("val2"))
got = sm2.String()
exp = `("symbol" ("parent" ("symbol" ("parent" ()) (SYM1 "val1"))) (SYM2 "val2"))`
if exp != got {
t.Errorf("sm2:\nexpected: %v,\n but got: %v", exp, got)
}
}