! Copyright (C) 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: accessors calendar combinators.short-circuit constructors eval initializers kernel math tools.test ; IN: constructors.tests TUPLE: stock-spread stock spread timestamp ; CONSTRUCTOR: stock-spread ( stock spread -- stock-spread ) now >>timestamp ; SYMBOL: AAPL [ t ] [ AAPL 1234 { [ stock>> AAPL eq? ] [ spread>> 1234 = ] [ timestamp>> timestamp? ] } 1&& ] unit-test TUPLE: ct1 a ; TUPLE: ct2 < ct1 b ; TUPLE: ct3 < ct2 c ; TUPLE: ct4 < ct3 d ; CONSTRUCTOR: ct1 ( a -- obj ) [ 1 + ] change-a ; CONSTRUCTOR: ct2 ( a b -- obj ) [ 1 + ] change-a ; CONSTRUCTOR: ct3 ( a b c -- obj ) [ 1 + ] change-a ; CONSTRUCTOR: ct4 ( a b c d -- obj ) [ 1 + ] change-a ; [ 1001 ] [ 1000 a>> ] unit-test [ 2 ] [ 0 0 a>> ] unit-test [ 3 ] [ 0 0 0 a>> ] unit-test [ 4 ] [ 0 0 0 0 a>> ] unit-test [ """USE: constructors IN: constructors.tests TUPLE: foo a b ; CONSTRUCTOR: foo ( a a -- obj ) ;""" eval( -- ) ] [ error>> repeated-constructor-parameters? ] must-fail-with [ """USE: constructors IN: constructors.tests TUPLE: foo a b ; CONSTRUCTOR: foo ( a c -- obj ) ;""" eval( -- ) ] [ error>> unknown-constructor-parameters? ] must-fail-with