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