Permalink
Browse files

Copy from original YAML::Tiny

  • Loading branch information...
1 parent 5cbabc6 commit 51ca86a044d35a44345401b0f1b2c30c7c86bac4 @bacek bacek committed Jan 27, 2011
Showing with 244 additions and 0 deletions.
  1. +244 −0 t/02_basic.t
View
244 t/02_basic.t
@@ -0,0 +1,244 @@
+#!/usr/bin/env parrot-nqp
+
+# Testing of basic document structures
+
+pir::load_bytecode("lib/YAML/Tiny.pbc");
+pir::load_bytecode("t/lib/Test.pbc");
+
+
+#####################################################################
+# Sample Testing
+
+# Test a completely empty document
+yaml_ok(
+ '',
+ [ ],
+ 'empty',
+);
+
+# Just a newline
+### YAML.pm has a bug where it dies on a single newline
+yaml_ok(
+ "\n\n",
+ [ ],
+ 'only_newlines',
+);
+
+# Just a comment
+yaml_ok(
+ "# comment\n",
+ [ ],
+ 'only_comment',
+);
+
+# Empty documents
+yaml_ok(
+ "---\n",
+ [ undef ],
+ 'only_header',
+ noyamlperl => 1,
+);
+yaml_ok(
+ "---\n---\n",
+ [ undef, undef ],
+ 'two_header',
+ noyamlperl => 1,
+);
+yaml_ok(
+ "--- ~\n",
+ [ undef ],
+ 'one_undef',
+ noyamlperl => 1,
+);
+yaml_ok(
+ "--- ~\n",
+ [ undef ],
+ 'one_undef2',
+ noyamlperl => 1,
+);
+yaml_ok(
+ "--- ~\n---\n",
+ [ undef, undef ],
+ 'two_undef',
+ noyamlperl => 1,
+);
+
+# Just a scalar
+yaml_ok(
+ "--- foo\n",
+ [ 'foo' ],
+ 'one_scalar',
+);
+yaml_ok(
+ "--- foo\n",
+ [ 'foo' ],
+ 'one_scalar2',
+);
+yaml_ok(
+ "--- foo\n--- bar\n",
+ [ 'foo', 'bar' ],
+ 'two_scalar',
+ noyamlperl => 1,
+);
+
+# Simple lists
+yaml_ok(
+ "---\n- foo\n",
+ [ [ 'foo' ] ],
+ 'one_list1',
+);
+yaml_ok(
+ "---\n- foo\n- bar\n",
+ [ [ 'foo', 'bar' ] ],
+ 'one_list2',
+);
+yaml_ok(
+ "---\n- ~\n- bar\n",
+ [ [ undef, 'bar' ] ],
+ 'one_listundef',
+ noyamlperl => 1,
+);
+
+# Simple hashs
+yaml_ok(
+ "---\nfoo: bar\n",
+ [ { foo => 'bar' } ],
+ 'one_hash1',
+);
+
+yaml_ok(
+ "---\nfoo: bar\nthis: ~\n",
+ [ { this => undef, foo => 'bar' } ],
+ 'one_hash2',
+ noyamlperl => 1,
+);
+
+# Simple array inside a hash with an undef
+yaml_ok(
+ q{---
+foo:
+ - bar
+ - ~
+ - baz
+},
+ [ { foo => [ 'bar', undef, 'baz' ] } ],
+ 'array_in_hash',
+ noyamlperl => 1,
+);
+
+# Simple hash inside a hash with an undef
+yaml_ok(
+ q{---
+foo: ~
+bar:
+ foo: bar
+},
+ [ { foo => undef, bar => { foo => 'bar' } } ],
+ 'hash_in_hash',
+ noyamlperl => 1,
+);
+
+# Mixed hash and scalars inside an array
+yaml_ok(
+ q{---
+-
+ foo: ~
+ this: that
+- foo
+- ~
+-
+ foo: bar
+ this: that
+},
+ [ [
+ { foo => undef, this => 'that' },
+ 'foo',
+ undef,
+ { foo => 'bar', this => 'that' },
+ ] ],
+ 'hash_in_array',
+ noyamlperl => 1,
+);
+
+# Simple single quote
+yaml_ok(
+ "---\n- 'foo'\n",
+ [ [ 'foo' ] ],
+ 'single_quote1',
+);
+yaml_ok(
+ "---\n- ' '\n",
+ [ [ ' ' ] ],
+ 'single_spaces',
+);
+yaml_ok(
+ "---\n- ''\n",
+ [ [ '' ] ],
+ 'single_null',
+);
+
+# Double quotes
+yaml_ok(
+ "--- \" \"\n",
+ [ ' ' ],
+ "only_spaces",
+ noyamlpm => 1,
+ noyamlperl => 1,
+);
+
+yaml_ok(
+ "--- \" foo\"\n--- \"bar \"\n",
+ [ " foo", "bar " ],
+ "leading_trailing_spaces",
+ noyamlpm => 1,
+ noyamlperl => 1,
+);
+
+# Implicit document start
+yaml_ok(
+ "foo: bar\n",
+ [ { foo => 'bar' } ],
+ 'implicit_hash',
+);
+yaml_ok(
+ "- foo\n",
+ [ [ 'foo' ] ],
+ 'implicit_array',
+);
+
+# Inline nested hash
+yaml_ok(
+ q{
+---
+- ~
+- foo: bar
+ this: that
+- baz
+},
+ [ [ undef, { foo => 'bar', this => 'that' }, 'baz' ] ],
+ 'inline_nested_hash',
+ noyamlperl => 1,
+);
+
+# Empty comments
+yaml_ok(
+ "---\n- foo\n#\n- bar\n",
+ [ [ 'foo', 'bar' ] ],
+ 'empty_comment_in_list',
+);
+
+yaml_ok(
+ "---\nfoo: bar\n# foo\none: two\n",
+ [ { foo => 'bar', one => 'two' } ],
+ 'empty_comment_in_hash',
+);
+
+# Complex keys
+#yaml_ok(
+# "---\na b: c d\n",
+# [ { 'a b' => 'c d' } ],
+# 'key_with_whitespace',
+#);
+
+done_testing();
+

0 comments on commit 51ca86a

Please sign in to comment.