]> gitweb.factorcode.org Git - factor.git/blob - basis/xml/dispatch/dispatch-tests.factor
Merge branch 'master' into experimental
[factor.git] / basis / xml / dispatch / dispatch-tests.factor
1 ! Copyright (C) 2005, 2009 Daniel Ehrenberg
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: xml io kernel math sequences strings xml.utilities
4 tools.test math.parser xml.dispatch ;
5 IN: xml.dispatch.tests
6
7 PROCESS: calculate ( tag -- n )
8
9 : calc-2children ( tag -- n n )
10     children-tags first2 [ calculate ] dip calculate ;
11
12 TAG: number calculate
13     children>string string>number ;
14 TAG: add calculate
15     calc-2children + ;
16 TAG: minus calculate
17     calc-2children - ;
18 TAG: times calculate
19     calc-2children * ;
20 TAG: divide calculate
21     calc-2children / ;
22 TAG: neg calculate
23     children-tags first calculate neg ;
24
25 : calc-arith ( string -- n )
26     string>xml first-child-tag calculate ;
27
28 [ 32 ] [
29     "<math><times><add><number>1</number><number>3</number></add><neg><number>-8</number></neg></times></math>"
30     calc-arith
31 ] unit-test