### ----------------------------------------------------
### -- Format::Lisp
### -- Licenses: Artistic-2.0
### -- Authors: Jeffrey Goff
### -- File: t/13-format-brace.rakutest
### ----------------------------------------------------
### -- Chunk 2 of 2
 
	ok def-format-test(
		Q[~0:@{~A~:}],
		( [ 1, Q[A] ], [ 2, Q[B] ], [ 3 ], [ 4, Q[C], Q[D] ] ),
		Q[],
		4
	), Q[format.:@.7];
	)

	#`(
	# (def-format-test format.\:@.8
	#   "~#:@{A~:}" (nil nil nil) "AAA")
	# 
	ok def-format-test(
		Q[~#:@{A~:}], ( Nil, Nil, Nil ), Q[AAA]
	), Q[format.:@.8];
	)

	#`(
	# (def-format-test format.\:@.9
	#   "~v:@{~A~}" (nil '(1) '(2) '(3)) "123")
	# 
	ok def-format-test(
		Q[~v:@{~A~}], ( Nil, [ 1 ], [ 2 ], [ 3 ] ), Q[123]
	), Q[format.:@.9];
	)

	#`(
	# (deftest format.\:@.10
	#   (loop for i from 0 to 10
	#         for x = nil then (cons (list i) x)
	#         collect
	#         (apply #Q[format nil "~V:@{~A~}" i (reverse x)))
	#   ("" "1" "12" "123" "1234" "12345" "123456" "1234567" "12345678"
	#    "123456789" "12345678910"))
	# 
	ok deftest( {
		my @collected;
		my @x;
		for 0 .. 10 -> $i {
			@x.append( $i );
			@collected.append(
				$*fl.format( Q[~V:@{~A~}], $i, @x.reverse )
			);
		}
		@collected;
	}, [	Q[],
		Q[1],
		Q[12],
		Q[123],
		Q[1234],
		Q[12345],
		Q[123456],
		Q[1234567],
		Q[12345678],
		Q[123456789],
		Q[12345678910]
	]
	), Q[format.:@.10];
	)

	#`(
	# (deftest formatter.\:@.10
	#   (let ((fn (formatter "~V@:{~A~}")))
	#     (loop for i from 0 to 10
	#           for x = nil then (cons (list i) x)
	#           for rest = (list 'a 'b)
	#           collect
	#           (with-output-to-string
	#             (s)
	#             (assert (equal (apply fn s i (append (reverse x) rest)) rest)))))
	#   ("" "1" "12" "123" "1234" "12345" "123456" "1234567" "12345678"
	#    "123456789" "12345678910"))
	# 
	ok deftest( {
		my @collected;
		my @x;
		for 0 .. 10 -> $i {
			@x.append( $i );
			@collected.append(
	#			$*fl.format( Q[~V:@{~A~}], $i, @x.reverse )
			);
		}
		@collected;
	}, [	Q[],
		Q[1],
		Q[12],
		Q[123],
		Q[1234],
		Q[12345],
		Q[123456],
		Q[1234567],
		Q[12345678],
		Q[123456789],
		Q[12345678910]
	]
	), Q[formatter.:@.10];
	)
}, Q[~:@{];

subtest {
	1;
	#`(
	# (deftest format.{.error.1
	#   (signals-type-error x 'A (format nil "~{~A~}" x))
	#   t)
	# 
	throws-like {
		my $x = :A; # XXX Not sure...
		$*fl.format( Q[~{~A~}], $x );
	}, X::Type-Error, Q[format.{.error.1];
	)

	#`(
	# (deftest format.{.error.2
	#   (signals-type-error x 1 (format nil "~{~A~}" x))
	#   t)
	# 
	throws-like {
		my $x = 1; # XXX Not sure...
		$*fl.format( Q[~{~A~}], $x );
	}, X::Type-Error, Q[format.{.error.2];
	)

	#`(
	# (deftest format.{.error.3
	#   (signals-type-error x "foo" (format nil "~{~A~}" x))
	#   t)
	# 
	throws-like {
		my $x = Q[foo]; # XXX Not sure...
		$*fl.format( Q[~{~A~}], $x );
	}, X::Type-Error, Q[format.{.error.3];
	)

	#`(
	# (deftest format.{.error.4
	#   (signals-type-error x #*01101 (format nil "~{~A~}" x))
	#   t)
	# 
	throws-like {
		my $x = 0b01101; # XXX Not sure...
		$*fl.format( Q[~{~A~}], $x );
	}, X::Type-Error, Q[format.{.error.4];
	)

	#`(
	# (deftest format.{.error.5
	#   (signals-error (format nil "~{~A~}" '(x y . z)) type-error)
	#   t)
	# 
	throws-like {
		my $x = :x; # XXX symbol
		$*fl.format( Q[~{~A~}], $x );
	}, X::Error, Q[format.{.error.5];
	)

	#`(
	# (deftest format.\:{.error.1
	#   (signals-error (format nil "~:{~A~}" '(x)) type-error)
	#   t)
	# 
	throws-like {
		my $x = :x; # XXX symbol
		$*fl.format( Q[~:{~A~}], $x );
	}, X::Error, Q[format.:{.error.1];
	)

	#`(
	# (deftest format.\:{.error.2
	#   (signals-type-error x 'x (format nil "~:{~A~}" x))
	#   t)
	# 
	throws-like {
		my $x = :x; # XXX symbol
		$*fl.format( Q[~:{~A~}], $x );
	}, X::Type-Error, Q[format.:{.error.2];
	)

	#`(
	# (deftest format.\:{.error.3
	#   (signals-error (format nil "~:{~A~}" '((x) . y)) type-error)
	#   t)
	# 
	throws-like {
		my $x = :x; # XXX symbol
		$*fl.format( Q[~:{~A~}], $x );
	}, X::Error, Q[format.:{.error.3];
	)

	#`(
	# (deftest format.\:{.error.4
	#   (signals-error (format nil "~:{~A~}" '("X")) type-error)
	#   t)
	# 
	throws-like {
		my $x = :x; # XXX symbol
		$*fl.format( Q[~:{~A~}], $x );
	}, X::Error, Q[format.:{.error.4];
	)

	#`(
	# (deftest format.\:{.error.5
	#   (signals-error (format nil "~:{~A~}" '(#(X Y Z))) type-error)
	#   t)
	# 
	throws-like {
		my $x = :x; # XXX symbol
		$*fl.format( Q[~:{~A~}], $x );
	}, X::Error, Q[format.:{.error.5];
	)

	#`(
	# (deftest format.\:@{.error.1
	#   (signals-type-error x 'x (format nil "~:@{~A~}" x))
	#   t)
	# 
	throws-like {
		my $x = :x; # XXX symbol
		$*fl.format( Q[~:@{~A~}], $x );
	}, X::Type-Error, Q[format.:@{.error.1];
	)

	#`(
	# (deftest format.\:@{.error.2
	#   (signals-type-error x 0 (format nil "~:@{~A~}" x))
	#   t)
	# 
	throws-like {
		my $x = 0;
		$*fl.format( Q[~:@{~A~}], $x );
	}, X::Type-Error, Q[format.:@{.error.2];
	)

	#`(
	# (deftest format.\:@{.error.3
	#   (signals-type-error x #*01101 (format nil "~:@{~A~}" x))
	#   t)
	# 
	throws-like {
		my $x = 0b01101;
		$*fl.format( Q[~:@{~A~}], $x );
	}, X::Type-Error, Q[format.:@{.error.3];
	)

	#`(
	# (deftest format.\:@{.error.4
	#   (signals-type-error x "abc" (format nil "~:@{~A~}" x))
	#   t)
	# 
	throws-like {
		my $x = Q[abc];
		$*fl.format( Q[~:@{~A~}], $x );
	}, X::Type-Error, Q[format.:@{.error.4];
	)

	#`(
	# (deftest format.\:@{.error.5
	#   (signals-error (format nil "~:@{~A ~A~}" '(x . y)) type-error)
	#   t)
	# 
	throws-like {
		my $x = Q[abc];
		$*fl.format( Q[~:@{~A ~A~}], $x );
	}, X::Type-Error, Q[format.:@{.error.5];
	)
}, Q[Error tests];

done-testing;

# vim: ft=perl6


