### ----------------------------------------------------
### -- Format::Lisp
### -- Licenses: Artistic-2.0
### -- Authors: Jeffrey Goff
### -- File: t/02-build-tree.rakutest
### ----------------------------------------------------
### -- Chunk 2 of 2
	];
)

	subtest {
		is-deeply $fl._parse( Q{~v<~>} ), [
			Format::Lisp::Directive::Angle.new(
				arguments => [ 'next' ]
			)
		];
		is-deeply $fl._parse( Q{~V<~>} ), [
			Format::Lisp::Directive::Angle.new(
				arguments => [ 'next' ]
			)
		];
		is-deeply $fl._parse( Q{~#<~>} ), [
			Format::Lisp::Directive::Angle.new(
				arguments => [ 'remaining' ]
			)
		];
		is-deeply $fl._parse( Q{~-2<~>} ), [
			Format::Lisp::Directive::Angle.new(
				arguments => [ -2 ]
			)
		];
		is-deeply $fl._parse( Q{~-1<~>} ), [
			Format::Lisp::Directive::Angle.new(
				arguments => [ -1 ]
			)
		];
		is-deeply $fl._parse( Q{~-0<~>} ), [
			Format::Lisp::Directive::Angle.new(
				arguments => [ 0 ]
			)
		];
		is-deeply $fl._parse( Q{~0<~>} ), [
			Format::Lisp::Directive::Angle.new(
				arguments => [ 0 ]
			)
		];
		is-deeply $fl._parse( Q{~+0<~>} ), [
			Format::Lisp::Directive::Angle.new(
				arguments => [ 0 ]
			)
		];
		is-deeply $fl._parse( Q{~+1<~>} ), [
			Format::Lisp::Directive::Angle.new(
				arguments => [ 1 ]
			)
		];
		is-deeply $fl._parse( Q{~+2<~>} ), [
			Format::Lisp::Directive::Angle.new(
				arguments => [ 2 ]
			)
		];
		is-deeply $fl._parse( Q{~'*<~>} ), [
			Format::Lisp::Directive::Angle.new(
				arguments => [ Q{*} ]
			)
		];
		is-deeply $fl._parse( Q{~'A<~>} ), [
			Format::Lisp::Directive::Angle.new(
				arguments => [ Q{A} ]
			)
		];
		is-deeply $fl._parse( Q{~'a<~>} ), [
			Format::Lisp::Directive::Angle.new(
				arguments => [ Q{a} ]
			)
		];
#`(
		is-deeply $fl._parse( Q{~'#<~>} ), [
			Format::Lisp::Directive::Angle.new(
				arguments => [ Q{#} ]
			)
		];
)
		is-deeply $fl._parse( Q{~'v<~>} ), [
			Format::Lisp::Directive::Angle.new(
				arguments => [ Q{v} ]
			)
		];
		is-deeply $fl._parse( Q{~'V<~>} ), [
			Format::Lisp::Directive::Angle.new(
				arguments => [ Q{V} ]
			)
		];
		is-deeply $fl._parse( Q{~',<~>} ), [
			Format::Lisp::Directive::Angle.new(
				arguments => [ Q{,} ]
			)
		];
#`(
		is-deeply $fl._parse( Q{~'\'<~>} ), [
			Format::Lisp::Directive::Angle.new(
				arguments => [ Q{'} ]
			)
		];
)

		done-testing;
			
	}, 'balanced directives';

	done-testing;
		
}, 'single argument';

subtest {
	is-deeply $fl._parse( Q{~v@:A} ), [
		Format::Lisp::Directive::A.new(
			at => True,
			colon => True,
			mincol => 'next'
		)
	];
	is-deeply $fl._parse( Q{~V@:A} ), [
		Format::Lisp::Directive::A.new(
			at => True,
			colon => True,
			mincol => 'next'
		)
	];
	is-deeply $fl._parse( Q{~#@:A} ), [
		Format::Lisp::Directive::A.new(
			at => True,
			colon => True,
			mincol => 'remaining'
		)
	];
	is-deeply $fl._parse( Q{~-2@:A} ), [
		Format::Lisp::Directive::A.new(
			at => True,
			colon => True,
			mincol => -2
		)
	];
	is-deeply $fl._parse( Q{~-1@:A} ), [
		Format::Lisp::Directive::A.new(
			at => True,
			colon => True,
			mincol => -1
		)
	];
	is-deeply $fl._parse( Q{~-0@:A} ), [
		Format::Lisp::Directive::A.new(
			at => True,
			colon => True,
			mincol => 0
		)
	];
	is-deeply $fl._parse( Q{~0@:A} ), [
		Format::Lisp::Directive::A.new(
			at => True,
			colon => True,
			mincol => 0
		)
	];
	is-deeply $fl._parse( Q{~+0@:A} ), [
		Format::Lisp::Directive::A.new(
			at => True,
			colon => True,
			mincol => 0
		)
	];
	is-deeply $fl._parse( Q{~+1@:A} ), [
		Format::Lisp::Directive::A.new(
			at => True,
			colon => True,
			mincol => 1
		)
	];
	is-deeply $fl._parse( Q{~+2@:A} ), [
		Format::Lisp::Directive::A.new(
			at => True,
			colon => True,
			mincol => 2
		)
	];
#`(
	is-deeply $fl._parse( Q{~'@@:A} ), [
		Format::Lisp::Directive::A.new(
			at => True,
			colon => True
		)
	];
)
	is-deeply $fl._parse( Q{~'A@:A} ), [
		Format::Lisp::Directive::A.new(
			at => True,
			colon => True,
			mincol => Q{A}
		)
	];
	is-deeply $fl._parse( Q{~'a@:a} ), [
		Format::Lisp::Directive::A.new(
			at => True,
			colon => True,
			mincol => Q{a}
		)
	];
#`(
	is-deeply $fl._parse( Q{~'#@:a} ), [
		Format::Lisp::Directive::A.new(
			at => True,
			colon => True,
			mincol => Q{'#}
		)
	];
)
	is-deeply $fl._parse( Q{~'v@:a} ), [
		Format::Lisp::Directive::A.new(
			at => True,
			colon => True,
			mincol => Q{v}
		)
	];
	is-deeply $fl._parse( Q{~'V@:a} ), [
		Format::Lisp::Directive::A.new(
			at => True,
			colon => True,
			mincol => Q{V}
		)
	];
	is-deeply $fl._parse( Q{~',@:A} ), [
		Format::Lisp::Directive::A.new(
			at => True,
			colon => True,
			mincol => Q{,}
		)
	];
#`(
	is-deeply $fl._parse( Q{~'\'@:A} ), [
		Format::Lisp::Directive::A.new(
			at => True,
			colon => True,
			mincol => Q{''}
		)
	];
)

	subtest {
		is-deeply $fl._parse( Q{~v@:<~>} ), [
			Format::Lisp::Directive::Angle.new(
				at => True,
				colon => True,
				mincol => 'next',
				arguments => [ 'next' ]
			)
		];
		is-deeply $fl._parse( Q{~V@:<~>} ), [
			Format::Lisp::Directive::Angle.new(
				at => True,
				colon => True,
				mincol => 'next',
				arguments => [ 'next' ]
			)
		];
		is-deeply $fl._parse( Q{~#@:<~>} ), [
			Format::Lisp::Directive::Angle.new(
				at => True,
				colon => True,
				mincol => 'remaining',
				arguments => [ 'remaining' ]
			)
		];
		is-deeply $fl._parse( Q{~-2@:<~>} ), [
			Format::Lisp::Directive::Angle.new(
				at => True,
				colon => True,
				mincol => -2,
				arguments => [ -2 ]
			)
		];
		is-deeply $fl._parse( Q{~-1@:<~>} ), [
			Format::Lisp::Directive::Angle.new(
				at => True,
				colon => True,
				mincol => -1,
				arguments => [ -1 ]
			)
		];
		is-deeply $fl._parse( Q{~-0@:<~>} ), [
			Format::Lisp::Directive::Angle.new(
				at => True,
				colon => True,
				mincol => 0,
				arguments => [ 0 ]
			)
		];
		is-deeply $fl._parse( Q{~0@:<~>} ), [
			Format::Lisp::Directive::Angle.new(
				at => True,
				colon => True,
				mincol => 0,
				arguments => [ 0 ]
			)
		];
		is-deeply $fl._parse( Q{~+0@:<~>} ), [
			Format::Lisp::Directive::Angle.new(
				at => True,
				colon => True,
				mincol => 0,
				arguments => [ 0 ]
			)
		];
		is-deeply $fl._parse( Q{~+1@:<~>} ), [
			Format::Lisp::Directive::Angle.new(
				at => True,
				colon => True,
				mincol => 1,
				arguments => [ 1 ]
			)
		];
		is-deeply $fl._parse( Q{~+2@:<~>} ), [
			Format::Lisp::Directive::Angle.new(
				at => True,
				colon => True,
				mincol => 2,
				arguments => [ 2 ]
			)
		];
		is-deeply $fl._parse( Q{~'*@:<~>} ), [
			Format::Lisp::Directive::Angle.new(
				at => True,
				colon => True,
				mincol => Q{*},
				arguments => [ Q{*} ]
			)
		];
		is-deeply $fl._parse( Q{~'A@:<~>} ), [
			Format::Lisp::Directive::Angle.new(
				at => True,
				colon => True,
				mincol => Q{A},
				arguments => [ Q{A} ]
			)
		];
		is-deeply $fl._parse( Q{~'a@:<~>} ), [
			Format::Lisp::Directive::Angle.new(
				at => True,
				colon => True,
				mincol => Q{a},
				arguments => [ Q{a} ]
			)
		];
#`(
		is-deeply $fl._parse( Q{~'#@:<~>} ), [
			Format::Lisp::Directive::Angle.new(
				at => True,
				colon => True,
				mincol => Q{'#},
				arguments => [ Q{'#} ]
			)
		];
)
		is-deeply $fl._parse( Q{~'v@:<~>} ), [
			Format::Lisp::Directive::Angle.new(
				at => True,
				colon => True,
				mincol => Q{v},
				arguments => [ Q{v} ]
			)
		];
		is-deeply $fl._parse( Q{~'V@:<~>} ), [
			Format::Lisp::Directive::Angle.new(
				at => True,
				colon => True,
				mincol => Q{V},
				arguments => [ Q{V} ]
			)
		];
		is-deeply $fl._parse( Q{~',@:<~>} ), [
			Format::Lisp::Directive::Angle.new(
				at => True,
				colon => True,
				mincol => Q{,},
				arguments => [ Q{,} ]
			)
		];
#`(
		is-deeply $fl._parse( Q{~'\'@:<~>} ), [
			Format::Lisp::Directive::Angle.new(
				at => True,
				colon => True,
				mincol => Q{''},
				arguments => [ Q{''} ]
			)
		];
)

		done-testing;
			
	}, 'balanced directives';

	done-testing;
		
}, 'single argument with options';

subtest {
	subtest {
		is-deeply $fl._parse( Q{~,A} ), [
			Format::Lisp::Directive::A.new(
			)
		];
		is-deeply $fl._parse( Q{~,vA} ), [
			Format::Lisp::Directive::A.new(
				colinc => 'next'
			)
		];
		is-deeply $fl._parse( Q{~,#A} ), [
			Format::Lisp::Directive::A.new(
				colinc => 'remaining'
			)
		];
		is-deeply $fl._parse( Q{~,0A} ), [
			Format::Lisp::Directive::A.new(
				colinc => 0
			)
		];

		done-testing;
	}, 'blank first argument';

	subtest {
		is-deeply $fl._parse( Q{~v,A} ), [
			Format::Lisp::Directive::A.new(
				mincol => 'next'
			)
		];
		is-deeply $fl._parse( Q{~v,vA} ), [
			Format::Lisp::Directive::A.new(
				mincol => 'next',
				colinc => 'next'
			)
		];
		is-deeply $fl._parse( Q{~v,#A} ), [
			Format::Lisp::Directive::A.new(
				mincol => 'next',
				colinc => 'remaining'
			)
		];
		is-deeply $fl._parse( Q{~v,0A} ), [
			Format::Lisp::Directive::A.new(
				mincol => 'next',
				colinc => 0
			)
		];

		done-testing;
	}, 'first argument "v"';

	subtest {
		is-deeply $fl._parse( Q{~#,A} ), [
			Format::Lisp::Directive::A.new(
				mincol => 'remaining'
			)
		];
		is-deeply $fl._parse( Q{~#,vA} ), [
			Format::Lisp::Directive::A.new(
				mincol => 'remaining',
				colinc => 'next'
			)
		];
		is-deeply $fl._parse( Q{~#,#A} ), [
			Format::Lisp::Directive::A.new(
				mincol => 'remaining',
				colinc => 'remaining'
			)
		];
		is-deeply $fl._parse( Q{~#,0A} ), [
			Format::Lisp::Directive::A.new(
				mincol => 'remaining',
				colinc => 0
			)
		];

		done-testing;
	}, 'first argument "#"';

	subtest {
		is-deeply $fl._parse( Q{~0,A} ), [
			Format::Lisp::Directive::A.new(
				mincol => 0
			)
		];
		is-deeply $fl._parse( Q{~0,vA} ), [
			Format::Lisp::Directive::A.new(
				mincol => 0,
				colinc => 'next'
			)
		];
		is-deeply $fl._parse( Q{~0,#A} ), [
			Format::Lisp::Directive::A.new(
				mincol => 0,
				colinc => 'remaining'
			)
		];
		is-deeply $fl._parse( Q{~0,0A} ), [
			Format::Lisp::Directive::A.new(
				mincol => 0,
				colinc => 0
			)
		];

		done-testing;
	}, 'first argument 0, XXX bogus';

	subtest {
		is-deeply $fl._parse( Q{~'*,A} ), [
			Format::Lisp::Directive::A.new(
				mincol => Q{*},
				colinc => 1
			)
		];
		is-deeply $fl._parse( Q{~'*,vA} ), [
			Format::Lisp::Directive::A.new(
				mincol => Q{*},
				colinc => 'next'
			)
		];
		is-deeply $fl._parse( Q{~'*,#A} ), [
			Format::Lisp::Directive::A.new(
				mincol => Q{*},
				colinc => 'remaining'
			)
		];
		is-deeply $fl._parse( Q{~'*,0A} ), [
			Format::Lisp::Directive::A.new(
				mincol => Q{*},
				colinc => 0
			)
		];

		done-testing;
	}, Q{first argument '* XXX bogus};

	done-testing;
		
}, 'multiple mixed arguments';

subtest {
	is-deeply $fl._parse( Q{~<~<~>~>} ), [
		Format::Lisp::Directive::Angle.new(
			children => [
				Format::Lisp::Directive::Angle.new
			]
		)
	];
	is-deeply $fl._parse( Q{~<~{~}~>} ), [
		Format::Lisp::Directive::Angle.new(
			children => [
				Format::Lisp::Directive::Brace.new
			]
		)
	];
	is-deeply $fl._parse( Q{~<~[~]~>} ), [
		Format::Lisp::Directive::Angle.new(
			children => [
				Format::Lisp::Directive::Bracket.new
			]
		)
	];
	is-deeply $fl._parse( Q{~<~(~)~>} ), [
		Format::Lisp::Directive::Angle.new(
			children => [
				Format::Lisp::Directive::Paren.new
			]
		)
	];

	done-testing;
		
}, 'nest balanced directive';

done-testing;

# vim: ft=perl6


