]> gitweb.factorcode.org Git - factor.git/blob - basis/core-text/core-text-tests.factor
factor: trim using lists
[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-text.fonts core-foundation
4 core-foundation.dictionaries destructors arrays kernel
5 generalizations math accessors core-foundation.utilities
6 combinators hashtables colors ;
7 IN: core-text.tests
8
9 : test-font ( name -- font )
10     [ >cf &CFRelease 0.0 f CTFontCreateWithName ] with-destructors ;
11
12 { } [ "Helvetica" test-font CFRelease ] unit-test
13
14 { } [
15     [
16         kCTFontAttributeName "Helvetica" test-font &CFRelease 2array 1array
17         <CFDictionary> &CFRelease drop
18     ] with-destructors
19 ] unit-test
20
21 :: test-typographic-bounds ( string font -- ? )
22     [
23         font test-font &CFRelease :> ctfont
24         string ctfont COLOR: white <CTLine> &CFRelease :> ctline
25         ctfont ctline compute-line-metrics {
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