Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenneth Schmidt committed Dec 3, 2009
1 parent 9b4f81d commit eddfbb0
Show file tree
Hide file tree
Showing 13 changed files with 169 additions and 10 deletions.
5 changes: 5 additions & 0 deletions test/data/collection/obj1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
'a' => 'a',
'c' => 'b',
'd' => 'Foo',
};
9 changes: 9 additions & 0 deletions test/data/collection/obj2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
'a' => 'a',
'b' => {
'a' => [ 'a', 'b', 'c' ],
'b' => 'a',
},
'c' => 'b',
'd' => 'Bar',
};
5 changes: 5 additions & 0 deletions test/data/collection_bogus/obj1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
'a' => 'a',
'c' => 'b',
'd' => 'Foo',
};
8 changes: 8 additions & 0 deletions test/data/collection_bogus/obj2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
'a' => 'a',
'b' => {
'a' => [ 'a', 'b', 'c' ],
'b' => 'a',
},
'c' => 'b',
};
34 changes: 34 additions & 0 deletions test/data/schemas/collection.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
class: Collection
type: map
mapping:
"a":
type: str
enum:
- a
- b
default: "a"
"b":
type: map
mapping:
"a":
type: seq
required: no
sequence:
- { type: str, unique: yes }
"b":
type: any
default: true
"c":
type: seq
required: no
sequence:
- { type: str, unique: yes }
"c":
type: str
pattern: /^(a|b|c)$/
required: no
"d":
type: str
name: HookOne
required: yes
33 changes: 33 additions & 0 deletions test/data/schemas/collection_bogus.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
class: Collection
mapping:
"a":
type: str
enum:
- a
- b
default: "a"
"b":
type: map
mapping:
"a":
type: seq
required: no
sequence:
- { type: str, unique: yes }
"b":
type: any
default: true
"c":
type: seq
required: no
sequence:
- { type: str, unique: yes }
"c":
type: str
pattern: /^(a|b|c)$/
required: no
"d":
type: str
name: HookOne
required: yes
18 changes: 18 additions & 0 deletions test/data/schemas/singleton.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- mode: yaml; tab-width: 2; indent-tabs-mode: nil; -*-
---
class: Config
type: map
mapping:
"a":
type: map
mapping:
"b": { type: int, required: yes }
"c": { type: int, required: yes }
"d": { type: int, required: yes }
"e": { type: int, required: yes }
"f":
type: seq
required: no
sequence:
- type: str
unique: yes
12 changes: 12 additions & 0 deletions test/data/singleton.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
'a' => {
'b' => 8,
'c' => 6,
'd' => 4,
'e' => 3,
'f' => [ 'a',
'b',
'c',
],
},
};
15 changes: 12 additions & 3 deletions test/helper.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
require 'rubygems'
require 'test/unit'

$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
TESTDIR = File.dirname(__FILE__)
$LOAD_PATH.unshift(TESTDIR)
$LOAD_PATH.unshift(File.join(TESTDIR, '..', 'lib'))

require 'yamo'

class Test::Unit::TestCase
class CollectionTest < Yamo::Collection
schema "#{TESTDIR}/data/schemas/collection.yaml"
objectdir "#{TESTDIR}/data/collection"
end

class SingletonTest < Yamo::Singleton
schema "#{TESTDIR}/data/schemas/singleton.yaml"
object "#{TESTDIR}/data/singleton.conf"
end
11 changes: 11 additions & 0 deletions test/test_collection.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'helper'

class TestCollection < Test::Unit::TestCase
def test_load
assert_equal(2, CollectionTest.entries.count)
assert_equal('obj1', CollectionTest.get("obj1").name)
assert_equal(1, CollectionTest.find_all { |c| c.d == "Bar" }.count)
obj = CollectionTest.entries.first
assert_equal(true, obj.b.b)
end
end
8 changes: 8 additions & 0 deletions test/test_singleton.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'helper'

class TestSingleton < Test::Unit::TestCase
def test_load
assert_equal(8, SingletonTest.instance.a.b)
assert_equal(3, SingletonTest.instance.a.f.count)
end
end
14 changes: 14 additions & 0 deletions test/test_validation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'helper'

class TestValidation < Test::Unit::TestCase
def test_load
CollectionTest.objectdir "#{TESTDIR}/data/collection_bogus"
assert_raise Yamo::ValidateError do
CollectionTest.entries
end

assert_raise Yamo::ValidateError do
CollectionTest.schema "#{TESTDIR}/data/schemas/collection_bogus.yaml"
end
end
end
7 changes: 0 additions & 7 deletions test/test_yamo.rb

This file was deleted.

0 comments on commit eddfbb0

Please sign in to comment.