From 97d60ac98d3ba9785ba1fb906a11748d064a40d7 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Tue, 23 Apr 2019 20:32:45 -0400 Subject: [PATCH] lang: Quote printed strings This quotes printed strings that contain special characters such as newline. This changes the output of some tests, but makes future tests that include a raw \n more appropriate. --- lang/interpret_test.go | 30 ++--- .../TestAstFunc1/duplicate_resource.graph | 20 +-- .../TestAstFunc1/empty-res-list-0.graph | 20 +-- lang/interpret_test/TestAstFunc1/hello0.graph | 14 +-- .../TestAstFunc1/importscope0.graph | 10 +- .../TestAstFunc1/importscope2.graph | 10 +- .../TestAstFunc1/metaparams0.graph | 44 +++---- .../TestAstFunc1/module_search1.graph | 118 +++++++++--------- .../TestAstFunc1/recursive_module1.graph | 118 +++++++++--------- lang/structs.go | 3 +- 10 files changed, 194 insertions(+), 193 deletions(-) diff --git a/lang/interpret_test.go b/lang/interpret_test.go index 0e8c41e0b6..46e64e4f6f 100644 --- a/lang/interpret_test.go +++ b/lang/interpret_test.go @@ -140,7 +140,7 @@ func TestAstFunc0(t *testing.T) { } { graph, _ := pgraph.NewGraph("g") - v1, v2, v3, v4, v5 := vtex("int(42)"), vtex("var(a)"), vtex("var(b)"), vtex("var(c)"), vtex("str(t)") + v1, v2, v3, v4, v5 := vtex("int(42)"), vtex("var(a)"), vtex("var(b)"), vtex("var(c)"), vtex(`str("t")`) e1, e2, e3 := edge("a"), edge("b"), edge("c") graph.AddVertex(&v1, &v2, &v3, &v4, &v5) graph.AddEdge(&v1, &v2, &e1) @@ -179,7 +179,7 @@ func TestAstFunc0(t *testing.T) { } { graph, _ := pgraph.NewGraph("g") - v1, v2, v3, v4, v5 := vtex("str(t)"), vtex("str(+)"), vtex("int(42)"), vtex("int(13)"), vtex(fmt.Sprintf("call:%s(str(+), int(42), int(13))", operatorFuncName)) + v1, v2, v3, v4, v5 := vtex(`str("t")`), vtex(`str("+")`), vtex("int(42)"), vtex("int(13)"), vtex(fmt.Sprintf(`call:%s(str("+"), int(42), int(13))`, operatorFuncName)) graph.AddVertex(&v1, &v2, &v3, &v4, &v5) e1, e2, e3 := edge("x"), edge("a"), edge("b") graph.AddEdge(&v2, &v5, &e1) @@ -199,10 +199,10 @@ func TestAstFunc0(t *testing.T) { } { graph, _ := pgraph.NewGraph("g") - v1, v2, v3 := vtex("str(t)"), vtex("str(-)"), vtex("str(+)") + v1, v2, v3 := vtex(`str("t")`), vtex(`str("-")`), vtex(`str("+")`) v4, v5, v6 := vtex("int(42)"), vtex("int(13)"), vtex("int(99)") - v7 := vtex(fmt.Sprintf("call:%s(str(+), int(42), int(13))", operatorFuncName)) - v8 := vtex(fmt.Sprintf("call:%s(str(-), call:%s(str(+), int(42), int(13)), int(99))", operatorFuncName, operatorFuncName)) + v7 := vtex(fmt.Sprintf(`call:%s(str("+"), int(42), int(13))`, operatorFuncName)) + v8 := vtex(fmt.Sprintf(`call:%s(str("-"), call:%s(str("+"), int(42), int(13)), int(99))`, operatorFuncName, operatorFuncName)) graph.AddVertex(&v1, &v2, &v3, &v4, &v5, &v6, &v7, &v8) e1, e2, e3 := edge("x"), edge("a"), edge("b") @@ -228,10 +228,10 @@ func TestAstFunc0(t *testing.T) { } { graph, _ := pgraph.NewGraph("g") - v1, v2 := vtex("bool(true)"), vtex("str(t)") + v1, v2 := vtex("bool(true)"), vtex(`str("t")`) v3, v4 := vtex("int(13)"), vtex("int(42)") v5, v6 := vtex("var(i)"), vtex("var(x)") - v7, v8 := vtex("str(+)"), vtex(fmt.Sprintf("call:%s(str(+), int(42), var(i))", operatorFuncName)) + v7, v8 := vtex(`str("+")`), vtex(fmt.Sprintf(`call:%s(str("+"), int(42), var(i))`, operatorFuncName)) e1, e2, e3, e4, e5 := edge("x"), edge("a"), edge("b"), edge("i"), edge("x") graph.AddVertex(&v1, &v2, &v3, &v4, &v5, &v6, &v7, &v8) @@ -285,8 +285,8 @@ func TestAstFunc0(t *testing.T) { } { graph, _ := pgraph.NewGraph("g") - v1, v2, v3 := vtex("str(hello)"), vtex("str(world)"), vtex("bool(true)") - v4, v5 := vtex("var(x)"), vtex("str(t)") + v1, v2, v3 := vtex(`str("hello")`), vtex(`str("world")`), vtex("bool(true)") + v4, v5 := vtex("var(x)"), vtex(`str("t")`) graph.AddVertex(&v1, &v2, &v3, &v4, &v5) e1 := edge("x") @@ -311,8 +311,8 @@ func TestAstFunc0(t *testing.T) { } { graph, _ := pgraph.NewGraph("g") - v1, v2, v3 := vtex("str(hello)"), vtex("str(world)"), vtex("bool(true)") - v4, v5 := vtex("var(x)"), vtex("str(t)") + v1, v2, v3 := vtex(`str("hello")`), vtex(`str("world")`), vtex("bool(true)") + v4, v5 := vtex("var(x)"), vtex(`str("t")`) graph.AddVertex(&v1, &v2, &v3, &v4, &v5) e1 := edge("x") @@ -339,9 +339,9 @@ func TestAstFunc0(t *testing.T) { //{ // graph, _ := pgraph.NewGraph("g") // v0 := vtex("bool(true)") - // v1, v2 := vtex("str(hello)"), vtex("str(world)") + // v1, v2 := vtex(`str("hello")`), vtex(`str("world")`) // v3, v4 := vtex("var(x)"), vtex("var(x)") // different vertices! - // v5, v6 := vtex("str(t1)"), vtex("str(t2)") + // v5, v6 := vtex(`str("t1")`), vtex(`str("t2")`) // // graph.AddVertex(&v0, &v1, &v2, &v3, &v4, &v5, &v6) // e1, e2 := edge("x"), edge("x") @@ -370,8 +370,8 @@ func TestAstFunc0(t *testing.T) { // // FIXME: blocked by: https://github.com/purpleidea/mgmt/issues/199 //{ // graph, _ := pgraph.NewGraph("g") - // v1, v2 := vtex("str(cowsay)"), vtex("str(cowsay)") - // v3, v4 := vtex("str(installed)"), vtex("str(newest)") + // v1, v2 := vtex(`str("cowsay")`), vtex(`str("cowsay")`) + // v3, v4 := vtex(`str("installed)`), vtex(`str("newest")`) // // graph.AddVertex(&v1, &v2, &v3, &v4) // diff --git a/lang/interpret_test/TestAstFunc1/duplicate_resource.graph b/lang/interpret_test/TestAstFunc1/duplicate_resource.graph index 193d5a444d..0c89c14f33 100644 --- a/lang/interpret_test/TestAstFunc1/duplicate_resource.graph +++ b/lang/interpret_test/TestAstFunc1/duplicate_resource.graph @@ -1,10 +1,10 @@ -Edge: str(hello world) -> call:fmt.printf(str(hello world)) # a -Vertex: call:fmt.printf(str(hello world)) -Vertex: str(/tmp/foo) -Vertex: str(/tmp/foo) -Vertex: str(cowsay) -Vertex: str(cowsay) -Vertex: str(hello world) -Vertex: str(hello world) -Vertex: str(installed) -Vertex: str(newest) +Edge: str("hello world") -> call:fmt.printf(str("hello world")) # a +Vertex: call:fmt.printf(str("hello world")) +Vertex: str("/tmp/foo") +Vertex: str("/tmp/foo") +Vertex: str("cowsay") +Vertex: str("cowsay") +Vertex: str("hello world") +Vertex: str("hello world") +Vertex: str("installed") +Vertex: str("newest") diff --git a/lang/interpret_test/TestAstFunc1/empty-res-list-0.graph b/lang/interpret_test/TestAstFunc1/empty-res-list-0.graph index d368c5f940..de0b977fb0 100644 --- a/lang/interpret_test/TestAstFunc1/empty-res-list-0.graph +++ b/lang/interpret_test/TestAstFunc1/empty-res-list-0.graph @@ -1,12 +1,12 @@ -Edge: list(str(hey)) -> var(names) # names -Edge: str(hello) -> list(str(hello), str(world)) # 0 -Edge: str(hey) -> list(str(hey)) # 0 -Edge: str(world) -> list(str(hello), str(world)) # 1 +Edge: list(str("hey")) -> var(names) # names +Edge: str("hello") -> list(str("hello"), str("world")) # 0 +Edge: str("hey") -> list(str("hey")) # 0 +Edge: str("world") -> list(str("hello"), str("world")) # 1 Vertex: list() -Vertex: list(str(hello), str(world)) -Vertex: list(str(hey)) -Vertex: str(hello) -Vertex: str(hey) -Vertex: str(name) -Vertex: str(world) +Vertex: list(str("hello"), str("world")) +Vertex: list(str("hey")) +Vertex: str("hello") +Vertex: str("hey") +Vertex: str("name") +Vertex: str("world") Vertex: var(names) diff --git a/lang/interpret_test/TestAstFunc1/hello0.graph b/lang/interpret_test/TestAstFunc1/hello0.graph index f485d3f4ce..17c548910e 100644 --- a/lang/interpret_test/TestAstFunc1/hello0.graph +++ b/lang/interpret_test/TestAstFunc1/hello0.graph @@ -1,8 +1,8 @@ -Vertex: call:fmt.printf(str(hello: %s), var(s)) -Vertex: str(greeting) -Vertex: str(hello: %s) -Vertex: str(world) +Edge: str("hello: %s") -> call:fmt.printf(str("hello: %s"), var(s)) # a +Edge: str("world") -> var(s) # s +Edge: var(s) -> call:fmt.printf(str("hello: %s"), var(s)) # b +Vertex: call:fmt.printf(str("hello: %s"), var(s)) +Vertex: str("greeting") +Vertex: str("hello: %s") +Vertex: str("world") Vertex: var(s) -Edge: str(hello: %s) -> call:fmt.printf(str(hello: %s), var(s)) # a -Edge: str(world) -> var(s) # s -Edge: var(s) -> call:fmt.printf(str(hello: %s), var(s)) # b diff --git a/lang/interpret_test/TestAstFunc1/importscope0.graph b/lang/interpret_test/TestAstFunc1/importscope0.graph index da5a1e0636..801e536611 100644 --- a/lang/interpret_test/TestAstFunc1/importscope0.graph +++ b/lang/interpret_test/TestAstFunc1/importscope0.graph @@ -1,10 +1,10 @@ Edge: call:os.is_debian() -> if(call:os.is_debian()) # c Edge: if(call:os.is_debian()) -> var(aaa) # aaa -Edge: str(bbb) -> if(call:os.is_debian()) # a -Edge: str(ccc) -> if(call:os.is_debian()) # b +Edge: str("bbb") -> if(call:os.is_debian()) # a +Edge: str("ccc") -> if(call:os.is_debian()) # b Vertex: call:os.is_debian() Vertex: if(call:os.is_debian()) -Vertex: str(bbb) -Vertex: str(ccc) -Vertex: str(hello) +Vertex: str("bbb") +Vertex: str("ccc") +Vertex: str("hello") Vertex: var(aaa) diff --git a/lang/interpret_test/TestAstFunc1/importscope2.graph b/lang/interpret_test/TestAstFunc1/importscope2.graph index da5a1e0636..801e536611 100644 --- a/lang/interpret_test/TestAstFunc1/importscope2.graph +++ b/lang/interpret_test/TestAstFunc1/importscope2.graph @@ -1,10 +1,10 @@ Edge: call:os.is_debian() -> if(call:os.is_debian()) # c Edge: if(call:os.is_debian()) -> var(aaa) # aaa -Edge: str(bbb) -> if(call:os.is_debian()) # a -Edge: str(ccc) -> if(call:os.is_debian()) # b +Edge: str("bbb") -> if(call:os.is_debian()) # a +Edge: str("ccc") -> if(call:os.is_debian()) # b Vertex: call:os.is_debian() Vertex: if(call:os.is_debian()) -Vertex: str(bbb) -Vertex: str(ccc) -Vertex: str(hello) +Vertex: str("bbb") +Vertex: str("ccc") +Vertex: str("hello") Vertex: var(aaa) diff --git a/lang/interpret_test/TestAstFunc1/metaparams0.graph b/lang/interpret_test/TestAstFunc1/metaparams0.graph index 599993bc8d..9a0146635e 100644 --- a/lang/interpret_test/TestAstFunc1/metaparams0.graph +++ b/lang/interpret_test/TestAstFunc1/metaparams0.graph @@ -1,20 +1,20 @@ -Edge: bool(false) -> struct(noop: bool(false); retry: int(-1); delay: int(0); poll: int(5); limit: float(4.2); burst: int(3); sema: list(str(foo:1), str(bar:3)); rewatch: bool(false); realize: bool(true); reverse: bool(true); autoedge: bool(true); autogroup: bool(true)) # noop -Edge: bool(false) -> struct(noop: bool(false); retry: int(-1); delay: int(0); poll: int(5); limit: float(4.2); burst: int(3); sema: list(str(foo:1), str(bar:3)); rewatch: bool(false); realize: bool(true); reverse: bool(true); autoedge: bool(true); autogroup: bool(true)) # rewatch -Edge: bool(true) -> struct(noop: bool(false); retry: int(-1); delay: int(0); poll: int(5); limit: float(4.2); burst: int(3); sema: list(str(foo:1), str(bar:3)); rewatch: bool(false); realize: bool(true); reverse: bool(true); autoedge: bool(true); autogroup: bool(true)) # autoedge -Edge: bool(true) -> struct(noop: bool(false); retry: int(-1); delay: int(0); poll: int(5); limit: float(4.2); burst: int(3); sema: list(str(foo:1), str(bar:3)); rewatch: bool(false); realize: bool(true); reverse: bool(true); autoedge: bool(true); autogroup: bool(true)) # autogroup -Edge: bool(true) -> struct(noop: bool(false); retry: int(-1); delay: int(0); poll: int(5); limit: float(4.2); burst: int(3); sema: list(str(foo:1), str(bar:3)); rewatch: bool(false); realize: bool(true); reverse: bool(true); autoedge: bool(true); autogroup: bool(true)) # realize -Edge: bool(true) -> struct(noop: bool(false); retry: int(-1); delay: int(0); poll: int(5); limit: float(4.2); burst: int(3); sema: list(str(foo:1), str(bar:3)); rewatch: bool(false); realize: bool(true); reverse: bool(true); autoedge: bool(true); autogroup: bool(true)) # reverse +Edge: bool(false) -> struct(noop: bool(false); retry: int(-1); delay: int(0); poll: int(5); limit: float(4.2); burst: int(3); sema: list(str("foo:1"), str("bar:3")); rewatch: bool(false); realize: bool(true); reverse: bool(true); autoedge: bool(true); autogroup: bool(true)) # noop +Edge: bool(false) -> struct(noop: bool(false); retry: int(-1); delay: int(0); poll: int(5); limit: float(4.2); burst: int(3); sema: list(str("foo:1"), str("bar:3")); rewatch: bool(false); realize: bool(true); reverse: bool(true); autoedge: bool(true); autogroup: bool(true)) # rewatch +Edge: bool(true) -> struct(noop: bool(false); retry: int(-1); delay: int(0); poll: int(5); limit: float(4.2); burst: int(3); sema: list(str("foo:1"), str("bar:3")); rewatch: bool(false); realize: bool(true); reverse: bool(true); autoedge: bool(true); autogroup: bool(true)) # autoedge +Edge: bool(true) -> struct(noop: bool(false); retry: int(-1); delay: int(0); poll: int(5); limit: float(4.2); burst: int(3); sema: list(str("foo:1"), str("bar:3")); rewatch: bool(false); realize: bool(true); reverse: bool(true); autoedge: bool(true); autogroup: bool(true)) # autogroup +Edge: bool(true) -> struct(noop: bool(false); retry: int(-1); delay: int(0); poll: int(5); limit: float(4.2); burst: int(3); sema: list(str("foo:1"), str("bar:3")); rewatch: bool(false); realize: bool(true); reverse: bool(true); autoedge: bool(true); autogroup: bool(true)) # realize +Edge: bool(true) -> struct(noop: bool(false); retry: int(-1); delay: int(0); poll: int(5); limit: float(4.2); burst: int(3); sema: list(str("foo:1"), str("bar:3")); rewatch: bool(false); realize: bool(true); reverse: bool(true); autoedge: bool(true); autogroup: bool(true)) # reverse Edge: bool(true) -> var(b) # b Edge: bool(true) -> var(b) # b -Edge: float(4.2) -> struct(noop: bool(false); retry: int(-1); delay: int(0); poll: int(5); limit: float(4.2); burst: int(3); sema: list(str(foo:1), str(bar:3)); rewatch: bool(false); realize: bool(true); reverse: bool(true); autoedge: bool(true); autogroup: bool(true)) # limit -Edge: int(-1) -> struct(noop: bool(false); retry: int(-1); delay: int(0); poll: int(5); limit: float(4.2); burst: int(3); sema: list(str(foo:1), str(bar:3)); rewatch: bool(false); realize: bool(true); reverse: bool(true); autoedge: bool(true); autogroup: bool(true)) # retry -Edge: int(0) -> struct(noop: bool(false); retry: int(-1); delay: int(0); poll: int(5); limit: float(4.2); burst: int(3); sema: list(str(foo:1), str(bar:3)); rewatch: bool(false); realize: bool(true); reverse: bool(true); autoedge: bool(true); autogroup: bool(true)) # delay -Edge: int(3) -> struct(noop: bool(false); retry: int(-1); delay: int(0); poll: int(5); limit: float(4.2); burst: int(3); sema: list(str(foo:1), str(bar:3)); rewatch: bool(false); realize: bool(true); reverse: bool(true); autoedge: bool(true); autogroup: bool(true)) # burst -Edge: int(5) -> struct(noop: bool(false); retry: int(-1); delay: int(0); poll: int(5); limit: float(4.2); burst: int(3); sema: list(str(foo:1), str(bar:3)); rewatch: bool(false); realize: bool(true); reverse: bool(true); autoedge: bool(true); autogroup: bool(true)) # poll -Edge: list(str(foo:1), str(bar:3)) -> struct(noop: bool(false); retry: int(-1); delay: int(0); poll: int(5); limit: float(4.2); burst: int(3); sema: list(str(foo:1), str(bar:3)); rewatch: bool(false); realize: bool(true); reverse: bool(true); autoedge: bool(true); autogroup: bool(true)) # sema -Edge: str(bar:3) -> list(str(foo:1), str(bar:3)) # 1 -Edge: str(foo:1) -> list(str(foo:1), str(bar:3)) # 0 -Edge: str(hello world) -> call:fmt.printf(str(hello world)) # a +Edge: float(4.2) -> struct(noop: bool(false); retry: int(-1); delay: int(0); poll: int(5); limit: float(4.2); burst: int(3); sema: list(str("foo:1"), str("bar:3")); rewatch: bool(false); realize: bool(true); reverse: bool(true); autoedge: bool(true); autogroup: bool(true)) # limit +Edge: int(-1) -> struct(noop: bool(false); retry: int(-1); delay: int(0); poll: int(5); limit: float(4.2); burst: int(3); sema: list(str("foo:1"), str("bar:3")); rewatch: bool(false); realize: bool(true); reverse: bool(true); autoedge: bool(true); autogroup: bool(true)) # retry +Edge: int(0) -> struct(noop: bool(false); retry: int(-1); delay: int(0); poll: int(5); limit: float(4.2); burst: int(3); sema: list(str("foo:1"), str("bar:3")); rewatch: bool(false); realize: bool(true); reverse: bool(true); autoedge: bool(true); autogroup: bool(true)) # delay +Edge: int(3) -> struct(noop: bool(false); retry: int(-1); delay: int(0); poll: int(5); limit: float(4.2); burst: int(3); sema: list(str("foo:1"), str("bar:3")); rewatch: bool(false); realize: bool(true); reverse: bool(true); autoedge: bool(true); autogroup: bool(true)) # burst +Edge: int(5) -> struct(noop: bool(false); retry: int(-1); delay: int(0); poll: int(5); limit: float(4.2); burst: int(3); sema: list(str("foo:1"), str("bar:3")); rewatch: bool(false); realize: bool(true); reverse: bool(true); autoedge: bool(true); autogroup: bool(true)) # poll +Edge: list(str("foo:1"), str("bar:3")) -> struct(noop: bool(false); retry: int(-1); delay: int(0); poll: int(5); limit: float(4.2); burst: int(3); sema: list(str("foo:1"), str("bar:3")); rewatch: bool(false); realize: bool(true); reverse: bool(true); autoedge: bool(true); autogroup: bool(true)) # sema +Edge: str("bar:3") -> list(str("foo:1"), str("bar:3")) # 1 +Edge: str("foo:1") -> list(str("foo:1"), str("bar:3")) # 0 +Edge: str("hello world") -> call:fmt.printf(str("hello world")) # a Vertex: bool(false) Vertex: bool(false) Vertex: bool(false) @@ -26,18 +26,18 @@ Vertex: bool(true) Vertex: bool(true) Vertex: bool(true) Vertex: bool(true) -Vertex: call:fmt.printf(str(hello world)) +Vertex: call:fmt.printf(str("hello world")) Vertex: float(4.2) Vertex: int(-1) Vertex: int(0) Vertex: int(3) Vertex: int(42) Vertex: int(5) -Vertex: list(str(foo:1), str(bar:3)) -Vertex: str(bar:3) -Vertex: str(foo:1) -Vertex: str(greeting) -Vertex: str(hello world) -Vertex: struct(noop: bool(false); retry: int(-1); delay: int(0); poll: int(5); limit: float(4.2); burst: int(3); sema: list(str(foo:1), str(bar:3)); rewatch: bool(false); realize: bool(true); reverse: bool(true); autoedge: bool(true); autogroup: bool(true)) +Vertex: list(str("foo:1"), str("bar:3")) +Vertex: str("bar:3") +Vertex: str("foo:1") +Vertex: str("greeting") +Vertex: str("hello world") +Vertex: struct(noop: bool(false); retry: int(-1); delay: int(0); poll: int(5); limit: float(4.2); burst: int(3); sema: list(str("foo:1"), str("bar:3")); rewatch: bool(false); realize: bool(true); reverse: bool(true); autoedge: bool(true); autogroup: bool(true)) Vertex: var(b) Vertex: var(b) diff --git a/lang/interpret_test/TestAstFunc1/module_search1.graph b/lang/interpret_test/TestAstFunc1/module_search1.graph index c2cb79e95e..53a8829078 100644 --- a/lang/interpret_test/TestAstFunc1/module_search1.graph +++ b/lang/interpret_test/TestAstFunc1/module_search1.graph @@ -1,31 +1,64 @@ -Vertex: call:_operator(str(+), int(42), var(third.three)) -Vertex: call:_operator(str(+), str(i am github.com/purpleidea/mgmt-example1/ and i contain: ), var(mod1.name)) -Vertex: call:_operator(str(+), str(i am github.com/purpleidea/mgmt-example1/ and i contain: ), var(mod1.name)) -Vertex: call:_operator(str(+), str(i am github.com/purpleidea/mgmt-example2/ and i contain: ), var(ex1)) -Vertex: call:_operator(str(+), str(this is module mod1 which contains: ), var(mod1.name)) -Vertex: call:fmt.printf(str(i imported local: %s), var(mod1.name)) -Vertex: call:fmt.printf(str(i imported remote: %s and %s), var(example1.name), var(example2.ex1)) -Vertex: call:fmt.printf(str(the answer is: %d), var(answer)) +Edge: call:_operator(str("+"), int(42), var(third.three)) -> var(h2g2.answer) # h2g2.answer +Edge: call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) -> var(example1.name) # example1.name +Edge: call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) -> var(example1.name) # example1.name +Edge: call:_operator(str("+"), str("this is module mod1 which contains: "), var(mod1.name)) -> var(mod1.name) # mod1.name +Edge: int(3) -> var(third.three) # third.three +Edge: int(42) -> call:_operator(str("+"), int(42), var(third.three)) # a +Edge: str("+") -> call:_operator(str("+"), int(42), var(third.three)) # x +Edge: str("+") -> call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) # x +Edge: str("+") -> call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) # x +Edge: str("+") -> call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example2/ and i contain: "), var(ex1)) # x +Edge: str("+") -> call:_operator(str("+"), str("this is module mod1 which contains: "), var(mod1.name)) # x +Edge: str("i am github.com/purpleidea/mgmt-example1/ and i contain: ") -> call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) # a +Edge: str("i am github.com/purpleidea/mgmt-example1/ and i contain: ") -> call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) # a +Edge: str("i am github.com/purpleidea/mgmt-example2/ and i contain: ") -> call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example2/ and i contain: "), var(ex1)) # a +Edge: str("i imported local: %s") -> call:fmt.printf(str("i imported local: %s"), var(mod1.name)) # a +Edge: str("i imported remote: %s and %s") -> call:fmt.printf(str("i imported remote: %s and %s"), var(example1.name), var(example2.ex1)) # a +Edge: str("the answer is: %d") -> call:fmt.printf(str("the answer is: %d"), var(answer)) # a +Edge: str("this is module mod1 which contains: ") -> call:_operator(str("+"), str("this is module mod1 which contains: "), var(mod1.name)) # a +Edge: str("this is the nested git module mod1") -> var(mod1.name) # mod1.name +Edge: str("this is the nested git module mod1") -> var(mod1.name) # mod1.name +Edge: str("this is the nested local module mod1") -> var(mod1.name) # mod1.name +Edge: var(answer) -> call:fmt.printf(str("the answer is: %d"), var(answer)) # b +Edge: var(ex1) -> call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example2/ and i contain: "), var(ex1)) # b +Edge: var(example1.name) -> call:fmt.printf(str("i imported remote: %s and %s"), var(example1.name), var(example2.ex1)) # b +Edge: var(example1.name) -> var(ex1) # ex1 +Edge: var(example1.name) -> var(example2.ex1) # example2.ex1 +Edge: var(example2.ex1) -> call:fmt.printf(str("i imported remote: %s and %s"), var(example1.name), var(example2.ex1)) # c +Edge: var(h2g2.answer) -> var(answer) # answer +Edge: var(mod1.name) -> call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) # b +Edge: var(mod1.name) -> call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) # b +Edge: var(mod1.name) -> call:_operator(str("+"), str("this is module mod1 which contains: "), var(mod1.name)) # b +Edge: var(mod1.name) -> call:fmt.printf(str("i imported local: %s"), var(mod1.name)) # b +Edge: var(third.three) -> call:_operator(str("+"), int(42), var(third.three)) # b +Vertex: call:_operator(str("+"), int(42), var(third.three)) +Vertex: call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) +Vertex: call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) +Vertex: call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example2/ and i contain: "), var(ex1)) +Vertex: call:_operator(str("+"), str("this is module mod1 which contains: "), var(mod1.name)) +Vertex: call:fmt.printf(str("i imported local: %s"), var(mod1.name)) +Vertex: call:fmt.printf(str("i imported remote: %s and %s"), var(example1.name), var(example2.ex1)) +Vertex: call:fmt.printf(str("the answer is: %d"), var(answer)) Vertex: int(3) Vertex: int(42) -Vertex: str(+) -Vertex: str(+) -Vertex: str(+) -Vertex: str(+) -Vertex: str(+) -Vertex: str(hello) -Vertex: str(hello2) -Vertex: str(hello3) -Vertex: str(i am github.com/purpleidea/mgmt-example1/ and i contain: ) -Vertex: str(i am github.com/purpleidea/mgmt-example1/ and i contain: ) -Vertex: str(i am github.com/purpleidea/mgmt-example2/ and i contain: ) -Vertex: str(i imported local: %s) -Vertex: str(i imported remote: %s and %s) -Vertex: str(the answer is: %d) -Vertex: str(this is module mod1 which contains: ) -Vertex: str(this is the nested git module mod1) -Vertex: str(this is the nested git module mod1) -Vertex: str(this is the nested local module mod1) +Vertex: str("+") +Vertex: str("+") +Vertex: str("+") +Vertex: str("+") +Vertex: str("+") +Vertex: str("hello") +Vertex: str("hello2") +Vertex: str("hello3") +Vertex: str("i am github.com/purpleidea/mgmt-example1/ and i contain: ") +Vertex: str("i am github.com/purpleidea/mgmt-example1/ and i contain: ") +Vertex: str("i am github.com/purpleidea/mgmt-example2/ and i contain: ") +Vertex: str("i imported local: %s") +Vertex: str("i imported remote: %s and %s") +Vertex: str("the answer is: %d") +Vertex: str("this is module mod1 which contains: ") +Vertex: str("this is the nested git module mod1") +Vertex: str("this is the nested git module mod1") +Vertex: str("this is the nested local module mod1") Vertex: var(answer) Vertex: var(ex1) Vertex: var(example1.name) @@ -37,36 +70,3 @@ Vertex: var(mod1.name) Vertex: var(mod1.name) Vertex: var(mod1.name) Vertex: var(third.three) -Edge: call:_operator(str(+), int(42), var(third.three)) -> var(h2g2.answer) # h2g2.answer -Edge: call:_operator(str(+), str(i am github.com/purpleidea/mgmt-example1/ and i contain: ), var(mod1.name)) -> var(example1.name) # example1.name -Edge: call:_operator(str(+), str(i am github.com/purpleidea/mgmt-example1/ and i contain: ), var(mod1.name)) -> var(example1.name) # example1.name -Edge: call:_operator(str(+), str(this is module mod1 which contains: ), var(mod1.name)) -> var(mod1.name) # mod1.name -Edge: int(3) -> var(third.three) # third.three -Edge: int(42) -> call:_operator(str(+), int(42), var(third.three)) # a -Edge: str(+) -> call:_operator(str(+), str(i am github.com/purpleidea/mgmt-example1/ and i contain: ), var(mod1.name)) # x -Edge: str(+) -> call:_operator(str(+), str(i am github.com/purpleidea/mgmt-example1/ and i contain: ), var(mod1.name)) # x -Edge: str(+) -> call:_operator(str(+), int(42), var(third.three)) # x -Edge: str(+) -> call:_operator(str(+), str(this is module mod1 which contains: ), var(mod1.name)) # x -Edge: str(+) -> call:_operator(str(+), str(i am github.com/purpleidea/mgmt-example2/ and i contain: ), var(ex1)) # x -Edge: str(i am github.com/purpleidea/mgmt-example1/ and i contain: ) -> call:_operator(str(+), str(i am github.com/purpleidea/mgmt-example1/ and i contain: ), var(mod1.name)) # a -Edge: str(i am github.com/purpleidea/mgmt-example1/ and i contain: ) -> call:_operator(str(+), str(i am github.com/purpleidea/mgmt-example1/ and i contain: ), var(mod1.name)) # a -Edge: str(i am github.com/purpleidea/mgmt-example2/ and i contain: ) -> call:_operator(str(+), str(i am github.com/purpleidea/mgmt-example2/ and i contain: ), var(ex1)) # a -Edge: str(i imported local: %s) -> call:fmt.printf(str(i imported local: %s), var(mod1.name)) # a -Edge: str(i imported remote: %s and %s) -> call:fmt.printf(str(i imported remote: %s and %s), var(example1.name), var(example2.ex1)) # a -Edge: str(the answer is: %d) -> call:fmt.printf(str(the answer is: %d), var(answer)) # a -Edge: str(this is module mod1 which contains: ) -> call:_operator(str(+), str(this is module mod1 which contains: ), var(mod1.name)) # a -Edge: str(this is the nested git module mod1) -> var(mod1.name) # mod1.name -Edge: str(this is the nested git module mod1) -> var(mod1.name) # mod1.name -Edge: str(this is the nested local module mod1) -> var(mod1.name) # mod1.name -Edge: var(answer) -> call:fmt.printf(str(the answer is: %d), var(answer)) # b -Edge: var(ex1) -> call:_operator(str(+), str(i am github.com/purpleidea/mgmt-example2/ and i contain: ), var(ex1)) # b -Edge: var(example1.name) -> var(ex1) # ex1 -Edge: var(example1.name) -> var(example2.ex1) # example2.ex1 -Edge: var(example1.name) -> call:fmt.printf(str(i imported remote: %s and %s), var(example1.name), var(example2.ex1)) # b -Edge: var(example2.ex1) -> call:fmt.printf(str(i imported remote: %s and %s), var(example1.name), var(example2.ex1)) # c -Edge: var(h2g2.answer) -> var(answer) # answer -Edge: var(mod1.name) -> call:_operator(str(+), str(i am github.com/purpleidea/mgmt-example1/ and i contain: ), var(mod1.name)) # b -Edge: var(mod1.name) -> call:fmt.printf(str(i imported local: %s), var(mod1.name)) # b -Edge: var(mod1.name) -> call:_operator(str(+), str(this is module mod1 which contains: ), var(mod1.name)) # b -Edge: var(mod1.name) -> call:_operator(str(+), str(i am github.com/purpleidea/mgmt-example1/ and i contain: ), var(mod1.name)) # b -Edge: var(third.three) -> call:_operator(str(+), int(42), var(third.three)) # b diff --git a/lang/interpret_test/TestAstFunc1/recursive_module1.graph b/lang/interpret_test/TestAstFunc1/recursive_module1.graph index c2cb79e95e..53a8829078 100644 --- a/lang/interpret_test/TestAstFunc1/recursive_module1.graph +++ b/lang/interpret_test/TestAstFunc1/recursive_module1.graph @@ -1,31 +1,64 @@ -Vertex: call:_operator(str(+), int(42), var(third.three)) -Vertex: call:_operator(str(+), str(i am github.com/purpleidea/mgmt-example1/ and i contain: ), var(mod1.name)) -Vertex: call:_operator(str(+), str(i am github.com/purpleidea/mgmt-example1/ and i contain: ), var(mod1.name)) -Vertex: call:_operator(str(+), str(i am github.com/purpleidea/mgmt-example2/ and i contain: ), var(ex1)) -Vertex: call:_operator(str(+), str(this is module mod1 which contains: ), var(mod1.name)) -Vertex: call:fmt.printf(str(i imported local: %s), var(mod1.name)) -Vertex: call:fmt.printf(str(i imported remote: %s and %s), var(example1.name), var(example2.ex1)) -Vertex: call:fmt.printf(str(the answer is: %d), var(answer)) +Edge: call:_operator(str("+"), int(42), var(third.three)) -> var(h2g2.answer) # h2g2.answer +Edge: call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) -> var(example1.name) # example1.name +Edge: call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) -> var(example1.name) # example1.name +Edge: call:_operator(str("+"), str("this is module mod1 which contains: "), var(mod1.name)) -> var(mod1.name) # mod1.name +Edge: int(3) -> var(third.three) # third.three +Edge: int(42) -> call:_operator(str("+"), int(42), var(third.three)) # a +Edge: str("+") -> call:_operator(str("+"), int(42), var(third.three)) # x +Edge: str("+") -> call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) # x +Edge: str("+") -> call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) # x +Edge: str("+") -> call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example2/ and i contain: "), var(ex1)) # x +Edge: str("+") -> call:_operator(str("+"), str("this is module mod1 which contains: "), var(mod1.name)) # x +Edge: str("i am github.com/purpleidea/mgmt-example1/ and i contain: ") -> call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) # a +Edge: str("i am github.com/purpleidea/mgmt-example1/ and i contain: ") -> call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) # a +Edge: str("i am github.com/purpleidea/mgmt-example2/ and i contain: ") -> call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example2/ and i contain: "), var(ex1)) # a +Edge: str("i imported local: %s") -> call:fmt.printf(str("i imported local: %s"), var(mod1.name)) # a +Edge: str("i imported remote: %s and %s") -> call:fmt.printf(str("i imported remote: %s and %s"), var(example1.name), var(example2.ex1)) # a +Edge: str("the answer is: %d") -> call:fmt.printf(str("the answer is: %d"), var(answer)) # a +Edge: str("this is module mod1 which contains: ") -> call:_operator(str("+"), str("this is module mod1 which contains: "), var(mod1.name)) # a +Edge: str("this is the nested git module mod1") -> var(mod1.name) # mod1.name +Edge: str("this is the nested git module mod1") -> var(mod1.name) # mod1.name +Edge: str("this is the nested local module mod1") -> var(mod1.name) # mod1.name +Edge: var(answer) -> call:fmt.printf(str("the answer is: %d"), var(answer)) # b +Edge: var(ex1) -> call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example2/ and i contain: "), var(ex1)) # b +Edge: var(example1.name) -> call:fmt.printf(str("i imported remote: %s and %s"), var(example1.name), var(example2.ex1)) # b +Edge: var(example1.name) -> var(ex1) # ex1 +Edge: var(example1.name) -> var(example2.ex1) # example2.ex1 +Edge: var(example2.ex1) -> call:fmt.printf(str("i imported remote: %s and %s"), var(example1.name), var(example2.ex1)) # c +Edge: var(h2g2.answer) -> var(answer) # answer +Edge: var(mod1.name) -> call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) # b +Edge: var(mod1.name) -> call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) # b +Edge: var(mod1.name) -> call:_operator(str("+"), str("this is module mod1 which contains: "), var(mod1.name)) # b +Edge: var(mod1.name) -> call:fmt.printf(str("i imported local: %s"), var(mod1.name)) # b +Edge: var(third.three) -> call:_operator(str("+"), int(42), var(third.three)) # b +Vertex: call:_operator(str("+"), int(42), var(third.three)) +Vertex: call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) +Vertex: call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example1/ and i contain: "), var(mod1.name)) +Vertex: call:_operator(str("+"), str("i am github.com/purpleidea/mgmt-example2/ and i contain: "), var(ex1)) +Vertex: call:_operator(str("+"), str("this is module mod1 which contains: "), var(mod1.name)) +Vertex: call:fmt.printf(str("i imported local: %s"), var(mod1.name)) +Vertex: call:fmt.printf(str("i imported remote: %s and %s"), var(example1.name), var(example2.ex1)) +Vertex: call:fmt.printf(str("the answer is: %d"), var(answer)) Vertex: int(3) Vertex: int(42) -Vertex: str(+) -Vertex: str(+) -Vertex: str(+) -Vertex: str(+) -Vertex: str(+) -Vertex: str(hello) -Vertex: str(hello2) -Vertex: str(hello3) -Vertex: str(i am github.com/purpleidea/mgmt-example1/ and i contain: ) -Vertex: str(i am github.com/purpleidea/mgmt-example1/ and i contain: ) -Vertex: str(i am github.com/purpleidea/mgmt-example2/ and i contain: ) -Vertex: str(i imported local: %s) -Vertex: str(i imported remote: %s and %s) -Vertex: str(the answer is: %d) -Vertex: str(this is module mod1 which contains: ) -Vertex: str(this is the nested git module mod1) -Vertex: str(this is the nested git module mod1) -Vertex: str(this is the nested local module mod1) +Vertex: str("+") +Vertex: str("+") +Vertex: str("+") +Vertex: str("+") +Vertex: str("+") +Vertex: str("hello") +Vertex: str("hello2") +Vertex: str("hello3") +Vertex: str("i am github.com/purpleidea/mgmt-example1/ and i contain: ") +Vertex: str("i am github.com/purpleidea/mgmt-example1/ and i contain: ") +Vertex: str("i am github.com/purpleidea/mgmt-example2/ and i contain: ") +Vertex: str("i imported local: %s") +Vertex: str("i imported remote: %s and %s") +Vertex: str("the answer is: %d") +Vertex: str("this is module mod1 which contains: ") +Vertex: str("this is the nested git module mod1") +Vertex: str("this is the nested git module mod1") +Vertex: str("this is the nested local module mod1") Vertex: var(answer) Vertex: var(ex1) Vertex: var(example1.name) @@ -37,36 +70,3 @@ Vertex: var(mod1.name) Vertex: var(mod1.name) Vertex: var(mod1.name) Vertex: var(third.three) -Edge: call:_operator(str(+), int(42), var(third.three)) -> var(h2g2.answer) # h2g2.answer -Edge: call:_operator(str(+), str(i am github.com/purpleidea/mgmt-example1/ and i contain: ), var(mod1.name)) -> var(example1.name) # example1.name -Edge: call:_operator(str(+), str(i am github.com/purpleidea/mgmt-example1/ and i contain: ), var(mod1.name)) -> var(example1.name) # example1.name -Edge: call:_operator(str(+), str(this is module mod1 which contains: ), var(mod1.name)) -> var(mod1.name) # mod1.name -Edge: int(3) -> var(third.three) # third.three -Edge: int(42) -> call:_operator(str(+), int(42), var(third.three)) # a -Edge: str(+) -> call:_operator(str(+), str(i am github.com/purpleidea/mgmt-example1/ and i contain: ), var(mod1.name)) # x -Edge: str(+) -> call:_operator(str(+), str(i am github.com/purpleidea/mgmt-example1/ and i contain: ), var(mod1.name)) # x -Edge: str(+) -> call:_operator(str(+), int(42), var(third.three)) # x -Edge: str(+) -> call:_operator(str(+), str(this is module mod1 which contains: ), var(mod1.name)) # x -Edge: str(+) -> call:_operator(str(+), str(i am github.com/purpleidea/mgmt-example2/ and i contain: ), var(ex1)) # x -Edge: str(i am github.com/purpleidea/mgmt-example1/ and i contain: ) -> call:_operator(str(+), str(i am github.com/purpleidea/mgmt-example1/ and i contain: ), var(mod1.name)) # a -Edge: str(i am github.com/purpleidea/mgmt-example1/ and i contain: ) -> call:_operator(str(+), str(i am github.com/purpleidea/mgmt-example1/ and i contain: ), var(mod1.name)) # a -Edge: str(i am github.com/purpleidea/mgmt-example2/ and i contain: ) -> call:_operator(str(+), str(i am github.com/purpleidea/mgmt-example2/ and i contain: ), var(ex1)) # a -Edge: str(i imported local: %s) -> call:fmt.printf(str(i imported local: %s), var(mod1.name)) # a -Edge: str(i imported remote: %s and %s) -> call:fmt.printf(str(i imported remote: %s and %s), var(example1.name), var(example2.ex1)) # a -Edge: str(the answer is: %d) -> call:fmt.printf(str(the answer is: %d), var(answer)) # a -Edge: str(this is module mod1 which contains: ) -> call:_operator(str(+), str(this is module mod1 which contains: ), var(mod1.name)) # a -Edge: str(this is the nested git module mod1) -> var(mod1.name) # mod1.name -Edge: str(this is the nested git module mod1) -> var(mod1.name) # mod1.name -Edge: str(this is the nested local module mod1) -> var(mod1.name) # mod1.name -Edge: var(answer) -> call:fmt.printf(str(the answer is: %d), var(answer)) # b -Edge: var(ex1) -> call:_operator(str(+), str(i am github.com/purpleidea/mgmt-example2/ and i contain: ), var(ex1)) # b -Edge: var(example1.name) -> var(ex1) # ex1 -Edge: var(example1.name) -> var(example2.ex1) # example2.ex1 -Edge: var(example1.name) -> call:fmt.printf(str(i imported remote: %s and %s), var(example1.name), var(example2.ex1)) # b -Edge: var(example2.ex1) -> call:fmt.printf(str(i imported remote: %s and %s), var(example1.name), var(example2.ex1)) # c -Edge: var(h2g2.answer) -> var(answer) # answer -Edge: var(mod1.name) -> call:_operator(str(+), str(i am github.com/purpleidea/mgmt-example1/ and i contain: ), var(mod1.name)) # b -Edge: var(mod1.name) -> call:fmt.printf(str(i imported local: %s), var(mod1.name)) # b -Edge: var(mod1.name) -> call:_operator(str(+), str(this is module mod1 which contains: ), var(mod1.name)) # b -Edge: var(mod1.name) -> call:_operator(str(+), str(i am github.com/purpleidea/mgmt-example1/ and i contain: ), var(mod1.name)) # b -Edge: var(third.three) -> call:_operator(str(+), int(42), var(third.three)) # b diff --git a/lang/structs.go b/lang/structs.go index 261206da71..4273664471 100644 --- a/lang/structs.go +++ b/lang/structs.go @@ -22,6 +22,7 @@ import ( "fmt" "reflect" "sort" + "strconv" "strings" "github.com/purpleidea/mgmt/engine" @@ -3554,7 +3555,7 @@ type ExprStr struct { func (obj *ExprStr) Apply(fn func(interfaces.Node) error) error { return fn(obj) } // String returns a short representation of this expression. -func (obj *ExprStr) String() string { return fmt.Sprintf("str(%s)", obj.V) } +func (obj *ExprStr) String() string { return fmt.Sprintf("str(%s)", strconv.Quote(obj.V)) } // Init initializes this branch of the AST, and returns an error if it fails to // validate.