module simple-traversal-test
imports libstratego-lib
signature
  constructors
    F : Term * Term -> Term
    G : Term * Term -> Term
    A : Term 
    B : Term
strategies

  main = 
    test-suite(!"simple-traversal-test",
      test1;
      test2;
      test3
    )

  test1 =
    apply-test(!"test1a"
	, all(fail)
	, !A
	, !A
	);
    apply-and-fail(!"test1b"
	, all(fail)
	, !F(G(B,F(A,B)),F(B,A))
	)

  f(x) = F(x,id)

  test2 =
    apply-test(!"test2"
	, leaves(!A, all(fail))
	, !F(G(B,F(A,B)),F(B,A))
	, !F(G(A,F(A,A)),F(A,A))
	);
    apply-test(!"test2"
	, leaves(!A, all(fail), f)
	, !F(G(B,F(B,B)),F(B,B))
	, !F(G(A,F(A,B)),F(B,B))
	)

  test3 =
    apply-test(!"test3a"
	, where(new-counter => c1)
          ; debug; bottomup(debug; \ t -> t{<next-counter> c1} \; debug)
	, !F(G(B,F(A,B)),F(B,A))
	, !F(G(B{1},F(A{2},B{3}){4}){5},F(B{6},A{7}){8}){9}
	);
    apply-test(!"test3b"
	, where(new-counter => c2)
          ; topdown(\ t -> t{<next-counter> c2} \ )
	, !F(G(B,F(A,B)),F(B,A))
	, !F(G(B{3},F(A{5},B{6}){4}){2},F(B{8},A{9}){7}){1}
	)
