const assert = require('assert')
const r = require('./get_in_memory_rosmaro')

describe("composite", function () {

  it("allows transitions on different levels", async function () {

    var entered_BBB = false

    const model = r({
      type: "machine",
      entry_point: "B",
      states: [

        ["A", {
          type: "prototype",
          follow_arrow() {
            this.transition("a")
          }
        }, {a: "B"}],

        ["B", {
          type: "composite",
          states: [

            ["A", {
              type: "prototype",
              follow_arrow() {
                this.transition("a")
              }
            }],

            ["B", {
              type: "machine",
              entry_point: "A",
              states: [

                ["A", {
                  type: "prototype",
                  follow_arrow() {
                    this.transition("a")
                  }
                }, {a: "B"}],

                ["B", {
                  type: "prototype",
                  on_entry() {
                    entered_BBB = true
                  }
                }, {}]

              ]
            }]

          ]
        }, {a: "A"}]

      ]
    })

    await model.follow_arrow()
    const nodes1 = await model.nodes

    assert.deepEqual(["A"], nodes1)
    assert.equal(entered_BBB, true)

    await model.follow_arrow()
    const nodes2 = await model.nodes
    assert.deepEqual(["B:A", "B:B:B"], nodes2)

  })

})

@@ -109,16 +109,1224 @@
 n () %7B%0A%0A
+  it(%22allows many transactions withing left nodes%22, async function () %7B%0A%0A    const A = %7B%0A      type: %22prototype%22,%0A      on_entry() %7B%0A        this.transition(%22e%22)%0A      %7D%0A    %7D%0A%0A    const BA = %7B%0A      type: %22prototype%22,%0A      x() %7B%0A        this.transition(%22x%22)%0A      %7D%0A    %7D%0A%0A    const BB = %7B%0A      type: %22machine%22,%0A      entry_point: %22A%22,%0A      states: %5B%0A%0A        %5B%22A%22, %7B%0A          type: %22prototype%22,%0A          x() %7B%0A            this.transition(%22x%22)%0A          %7D%0A        %7D, %7Bx: %22B%22%7D%5D,%0A%0A        %5B%22B%22, %7B%0A          type: %22prototype%22,%0A          on_entry() %7B%0A            this.transition(%22e%22)%0A          %7D%0A        %7D, %7Be: %22C%22%7D%5D,%0A%0A        %5B%22C%22, %7B%0A          type: %22prototype%22,%0A          on_entry() %7B%0A            this.transition(%22e%22)%0A          %7D%0A        %7D, %7Be: %22D%22%7D%5D,%0A%0A        %5B%22D%22, %7B%0A          type: %22prototype%22%0A        %7D, %7B%7D%5D,%0A%0A      %5D%0A    %7D%0A%0A    const B = %7B%0A      type: %22composite%22,%0A      states: %5B%0A        %5B%22A%22, BA%5D,%0A        %5B%22B%22, BB%5D%0A      %5D%0A    %7D%0A%0A    const model = r(%7B%0A      type: %22machine%22,%0A      entry_point: %22B%22,%0A      states: %5B%0A        %5B%22A%22, A, %7Be: %22B%22%7D%5D,%0A        %5B%22B%22, B, %7Bx: %22A%22%7D%5D%0A      %5D%0A    %7D)%0A%0A    await model.x()%0A%0A    const nodes = await model.nodes%0A    assert.deepEqual(%5B%22B:A%22, %22B:B:D%22%5D, nodes)%0A%0A  %7D)%0A%0A
   it(%22al

test of many transitions among left nodes