]> gitweb.factorcode.org Git - factor.git/blob - basis/core-text/core-text-tests.factor
Merge branch 'master' into new_ui
[factor.git] / basis / core-text / core-text-tests.factor
1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: tools.test core-text core-foundation
4 core-foundation.dictionaries destructors
5 arrays kernel generalizations math accessors
6 core-foundation.utilities
7 combinators hashtables colors ;
8 IN: core-text.tests
9
10 : test-font ( name -- font )
11     [ >cf &CFRelease 0.0 f CTFontCreateWithName ] with-destructors ;
12
13 [ ] [ "Helvetica" test-font CFRelease ] unit-test
14
15 [ ] [
16     [
17         kCTFontAttributeName "Helvetica" test-font &CFRelease 2array 1array
18         <CFDictionary> &CFRelease drop
19     ] with-destructors
20 ] unit-test
21
22 : test-typographic-bounds ( string font -- ? )
23     [
24         test-font &CFRelease white <CTLine> &CFRelease
25         line-typographic-bounds {
26             [ width>> float? ]
27             [ ascent>> float? ]
28             [ descent>> float? ]
29             [ leading>> float? ]
30         } cleave and and and
31     ] with-destructors ;
32
33 [ t ] [ "Hello world" "Helvetica" test-typographic-bounds ] unit-test
34
35 [ t ] [ "Hello world" "Chicago" test-typographic-bounds ] unit-test
36
37 [ t ] [ "日本語" "Helvetica" test-typographic-bounds ] unit-test