##
## $Rev: 63 $
## $Release: 0.7.2 $
## copyright(c) 2005-2010 kuwata-lab all rights reserved.
##
---

- name:  databind1
  desc:  sequence of mapping
  schema: |
	type:  seq
	sequence:
	  - type:  map
	    class: My1::Address
	    mapping:
	     "name":  { type: str, required: yes }
	     "tel":   { type: str }
	     "email": { type: str }
	     "age":   { type: int }
	     "birth": { type: date }
	     "blood": { type: str, enum: [A, B, O, AB] }
  classdef*:
    ruby: |
        require 'kwalify/util/hashlike'
	module ::My1
	  class Address
	    include Kwalify::Util::HashLike
	    attr_accessor :name, :tel, :email, :age, :birth, :blood
	  end
	end

  data: |
	- name:	 Foo
	  tel:   012-345-7777
	  email: foo@mail.com
	  age:   15
	  birth: 1990-01-01
	  blood: A
	- name:	 Bar
	  tel:   012-345-8889
	  email: bar@mail.org
	  age:   14
	  birth: 1991-01-02
	- name:	 Foo
	  tel:   012-345-9999
	  email: baz@mail.net
	  age:   13
	  birth: 1992-01-03
	  blood: AB
  expected*:
    ruby: |
	[#<My1::Address:0x001
	  @age=15,
	  @birth=#<Date: 4895785/2,0,2299161>,
	  @blood="A",
	  @email="foo@mail.com",
	  @name="Foo",
	  @tel="012-345-7777">,
	 #<My1::Address:0x002
	  @age=14,
	  @birth=#<Date: 4896517/2,0,2299161>,
	  @email="bar@mail.org",
	  @name="Bar",
	  @tel="012-345-8889">,
	 #<My1::Address:0x003
	  @age=13,
	  @birth=#<Date: 4897249/2,0,2299161>,
	  @blood="AB",
	  @email="baz@mail.net",
	  @name="Foo",
	  @tel="012-345-9999">]
  locations:
	- [ "/0",        1,  3 ]
	- [ "/0/name",   1, 10 ]
	- [ "/0/tel",    2, 10 ]
	- [ "/0/email",  3, 10 ]
	- [ "/0/age",    4, 10 ]
	- [ "/0/birth",  5, 10 ]
	- [ "/0/blood",  6, 10 ]
	- [ "/1",        7,  3 ]
	- [ "/1/name",   7, 10 ]
	- [ "/1/tel",    8, 10 ]
	- [ "/1/email",  9, 10 ]
	- [ "/1/age",   10, 10 ]
	- [ "/1/birth", 11, 10 ]
	- [ "/2",       12,  3 ]
	- [ "/2/name",  12, 10 ]
	- [ "/2/tel",   13, 10 ]
	- [ "/2/email", 14, 10 ]
	- [ "/2/age",   15, 10 ]
	- [ "/2/birth", 16, 10 ]


- name:	 databind2
  desc:  recursive binding
  schema: &context_schema |
	type:  map
	class: My2::Context
	mapping:
	 "groups":
	    type:  seq
	    sequence:
	      - type:  map
	        class: My2::Group
	        mapping:
		 "name":
		    type:  str
		    required:  yes
		 "desc":
		    type:  str
		 "owner": &userschema
		    type:  map
		    class: My2::User
		    mapping:
		     "name":
		        type:  str
			required: yes
	             "desc":
		        type:  str
	             "gender":
		        type:  bool
		     "mail":
		        type:   str
		     "manager": *userschema
	 "users":
	    type: seq
	    sequence:
	      - *userschema
	
  classdef*: &context_classdef
    ruby: |
        require 'kwalify/util/hashlike'
	module ::My2
	
	  class Context
	    include Kwalify::Util::HashLike
	    attr_accessor :groups     # seq
	    attr_accessor :users      # seq
	  end
	
	  class Group
	    include Kwalify::Util::HashLike
	    attr_accessor :name       # str
	    attr_accessor :desc       # str
	    attr_accessor :owner      # map
	  end
	
	  class User
	    include Kwalify::Util::HashLike
	    attr_accessor :name       # str
	    attr_accessor :gender     # bool
	    attr_accessor :mail       # str
	    attr_accessor :desc       # str
	    attr_accessor :manager    # map
	  end
	
	end

  data: |
	groups:
	  - name:	admin
	    desc:	administrator group
	    owner: &root
	      name:	root
	      desc:	root user
	  - name:       users
	    desc:	user group
	    owner: &guest
	      name:	guest
	      desc:	guest user
	users:
	  - *root
	  - *guest
	  - &user1
	    name: user1
	  - name: user2
	    manager: *user1

  expected*:
    ruby: |
	#<My2::Context:0x001
	 @groups=
	  [#<My2::Group:0x002
	    @desc="administrator group",
	    @name="admin",
	    @owner=#<My2::User:0x003 @desc="root user", @name="root">>,
	   #<My2::Group:0x004
	    @desc="user group",
	    @name="users",
	    @owner=#<My2::User:0x005 @desc="guest user", @name="guest">>],
	 @users=
	  [#<My2::User:0x003 @desc="root user", @name="root">,
	   #<My2::User:0x005 @desc="guest user", @name="guest">,
	   #<My2::User:0x006 @name="user1">,
	   #<My2::User:0x007
	    @manager=#<My2::User:0x006 @name="user1">,
	    @name="user2">]>

  locations:
	- [ "/",                      1,  1 ]
	- [ "/groups",                2,  3 ]
	- [ "/groups/0",              2,  5 ]
	- [ "/groups/0/name",         2, 17 ]
	- [ "/groups/0/desc",         3, 17 ]
	- [ "/groups/0/owner",        4, 12 ]
	- [ "/groups/0/owner/name",   5, 17 ]
	- [ "/groups/0/owner/desc",   6, 17 ]
	- [ "/groups/1",              7,  5 ]
	- [ "/groups/1/name",         7, 17 ]
	- [ "/groups/1/desc",         8, 17 ]
	- [ "/groups/1/owner",        9, 12 ]
	- [ "/groups/1/owner/name",  10, 17 ]
	- [ "/groups/1/owner/desc",  11, 17 ]
	- [ "/users",                13,  3 ]
	- [ "/users/0",              13,  5 ]
	- [ "/users/0/name",          5, 17 ]
	- [ "/users/0/desc",          6, 17 ]
	- [ "/users/1",              14,  5 ]
	- [ "/users/1/name",         10, 17 ]
	- [ "/users/1/desc",         11, 17 ]
	- [ "/users/2",              15,  5 ]
	- [ "/users/2/name",         16, 11 ]
	- [ "/users/3",              17,  5 ]
	- [ "/users/3/name",         17, 11 ]
	- [ "/users/3/manager",      18, 14 ]
	- [ "/users/3/manager/name", 16, 11 ]


- name:	 databind3
  desc:  preceding alias
  testopts:  { preceding_alias: yes }
  schema:    *context_schema
  classdef*: *context_classdef
  data: |
	groups:
	  - name:	admin
	    desc:	administrator group
	    owner:      *root
	  - name:       users
	    desc:	user group
	    owner:      *guest
	users:
	  - &root
	    name:	root
	    desc:	root user
	  - &guest
	    name:	guest
	    desc:	guest user
	  - name:       user2
	    manager:    *user1
	  - &user1
	    name:       user1

  expected*:
    ruby: |
	#<My2::Context:0x001
	 @groups=
	  [#<My2::Group:0x002
	    @desc="administrator group",
	    @name="admin",
	    @owner=#<My2::User:0x003 @desc="root user", @name="root">>,
	   #<My2::Group:0x004
	    @desc="user group",
	    @name="users",
	    @owner=#<My2::User:0x005 @desc="guest user", @name="guest">>],
	 @users=
	  [#<My2::User:0x003 @desc="root user", @name="root">,
	   #<My2::User:0x005 @desc="guest user", @name="guest">,
	   #<My2::User:0x006
	    @manager=#<My2::User:0x007 @name="user1">,
	    @name="user2">,
	   #<My2::User:0x007 @name="user1">]>

  locations:
	- [ "/",                      1,  1 ]
	- [ "/groups",                2,  3 ]
	- [ "/groups/0",              2,  5 ]
	- [ "/groups/0/name",         2, 17 ]
	- [ "/groups/0/desc",         3, 17 ]
	- [ "/groups/0/owner",        4, 17 ]
	- [ "/groups/0/owner/name",  10, 17 ]
	- [ "/groups/0/owner/desc",  11, 17 ]
	- [ "/groups/1",              5,  5 ]
	- [ "/groups/1/name",         5, 17 ]
	- [ "/groups/1/desc",         6, 17 ]
	- [ "/groups/1/owner",        7, 17 ]
	- [ "/groups/1/owner/name",  13, 17 ]
	- [ "/groups/1/owner/desc",  14, 17 ]
	- [ "/users",                 9,  3 ]
	- [ "/users/0",               9,  5 ]
	- [ "/users/0/name",         10, 17 ]
	- [ "/users/0/desc",         11, 17 ]
	- [ "/users/1",              12,  5 ]
	- [ "/users/1/name",         13, 17 ]
	- [ "/users/1/desc",         14, 17 ]
	- [ "/users/2",              15,  5 ]
	- [ "/users/2/name",         15, 17 ]
	- [ "/users/2/manager",      16, 17 ]
	- [ "/users/2/manager/name", 18, 17 ]
	- [ "/users/3",              17,  5 ]
	- [ "/users/3/name",         18, 17 ]


- name:	 databind4
  desc:  default value
  schema: |
	type: map
	class: Config
	mapping:
	 "host":  {type: str, default: localhost}
	 "port":  {type: int, default: 80}
	 "user":  {type: str, required: true}
	 "pass":  {type: str, required: true}

  classdef*:
   "ruby": |
	require 'kwalify/util/hashlike'
	class Config
	  include Kwalify::Util::HashLike
	  def initialize
	    @host = 'localhost'
	    @port = 8080
	  end
	  attr_accessor :host, :port, :user, :pass
	end
   "java": |
  data: |
	#host:  localhost
	port:  8080
	user:  user1
	pass:  password1
  expected*:
   "ruby": |
	#<Config:0x001
	 @host="localhost",
	 @pass="password1",
	 @port=8080,
	 @user="user1">
  locations:
