123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- /*
- * ECAL
- *
- * Copyright 2020 Matthias Ladkau. All rights reserved.
- *
- * This Source Code Form is subject to the terms of the MIT
- * License, If a copy of the MIT License was not distributed with this
- * file, You can obtain one at https://opensource.org/licenses/MIT.
- */
- package scope
- import (
- "fmt"
- "testing"
- "devt.de/krotik/ecal/parser"
- )
- func TestNameFromASTNode(t *testing.T) {
- n, _ := parser.Parse("", "foo")
- if res := NameFromASTNode(n); res != "block: identifier (Line:1 Pos:1)" {
- t.Error("Unexpected result:", res)
- return
- }
- }
- func TestScopeConversion(t *testing.T) {
- vs := NewScope("foo")
- vs.SetValue("a", 1)
- vs.SetValue("b", 2)
- vs.SetValue("c", 3)
- vs2 := ToScope("foo", ToObject(vs))
- if vs.String() != vs2.String() {
- t.Error("Unexpected result:", vs.String(), vs2.String())
- return
- }
- }
- func TestConvertJSONToECALObject(t *testing.T) {
- testJSONStructure := map[string]interface{}{
- "foo": []interface{}{
- map[string]interface{}{
- "bar": "123",
- },
- },
- }
- res := ConvertJSONToECALObject(testJSONStructure)
- if typeString := fmt.Sprintf("%#v", res); typeString !=
- `map[interface {}]interface {}{"foo":[]interface {}{map[interface {}]interface {}{"bar":"123"}}}` {
- t.Error("Unexpected result:", typeString)
- return
- }
- res = ConvertECALToJSONObject(res)
- if typeString := fmt.Sprintf("%#v", res); typeString !=
- `map[string]interface {}{"foo":[]interface {}{map[string]interface {}{"bar":"123"}}}` {
- t.Error("Unexpected result:", typeString)
- return
- }
- testJSONStructure2 := map[interface{}]interface{}{"data": map[interface{}]interface{}{"obj": []map[string]interface{}{{"key": "LovelyRabbit"}}}}
- res = ConvertJSONToECALObject(testJSONStructure2)
- if typeString := fmt.Sprintf("%#v", res); typeString !=
- `map[interface {}]interface {}{"data":map[interface {}]interface {}{"obj":[]interface {}{map[interface {}]interface {}{"key":"LovelyRabbit"}}}}` {
- t.Error("Unexpected result:", typeString)
- return
- }
- res = ConvertECALToJSONObject(res)
- if typeString := fmt.Sprintf("%#v", res); typeString !=
- `map[string]interface {}{"data":map[string]interface {}{"obj":[]interface {}{map[string]interface {}{"key":"LovelyRabbit"}}}}` {
- t.Error("Unexpected result:", typeString)
- return
- }
- }
|