Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 79 lines (72 sloc) 3.006 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
; Copyright (c) Dave Ray, 2011. All rights reserved.

; The use and distribution terms for this software are covered by the
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
; which can be found in the file epl-v10.html at the root of this
; distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.

(ns seesaw.test.font
  (:use seesaw.font)
  (:use [lazytest.describe :only (describe it testing)]
        [lazytest.expect :only (expect)])
  (:import [java.awt Font]))

(describe font
  (it "can create a font from a font-spec"
    (let [f (font "ARIAL-BOLD-18")]
      (expect (= "ARIAL" (.getName f)))
      (expect (= 18 (.getSize f))))
      (expect (= Font/BOLD (.getStyle f))))
  (it "can create a bold font"
    (let [f (font :style :bold )]
      (expect (= Font/BOLD (.getStyle f)))))
  (it "can create a bold & italic font"
    (let [f (font :style #{:bold :italic} )]
      (expect (= (bit-or Font/BOLD Font/ITALIC) (.getStyle f)))))
  (it "can create a plain font"
    (let [f (font)]
      (expect (= Font/PLAIN (.getStyle f)))))
  (it "can create an italic font"
    (let [f (font :style :italic)]
      (expect (= Font/ITALIC (.getStyle f)))))
  (it "can create a font with a specific size"
    (let [f (font :size 40)]
      (expect (= 40 (.getSize f)))))
  (it "can create a font from a family keyword"
    (let [f (font :monospaced)]
      (expect (= "Monospaced" (.getFamily f)))))
  (it "can create a monospace font"
    (let [f (font :name :monospaced)]
      (expect (= Font/MONOSPACED (.getName f)))))
  (it "can create a serif font"
    (let [f (font :name :serif)]
      (expect (= Font/SERIF (.getName f)))))
  (it "can create a sans-serif font"
    (let [f (font :name :sans-serif)]
      (expect (= Font/SANS_SERIF (.getName f)))))
  (it "can create a font with a specific typeface"
    (let [f (font :name "Arial")]
      (expect (= "Arial" (.getName f)))))
  (it "can derive a font from another"
    (let [f (font :from (font :name "Arial") :size 33 :style :bold)]
      (expect (= 33 (.getSize f)))
      (expect (= Font/BOLD (.getStyle f)))
      (expect (= "Arial" (.getName f))))))

(describe to-font
  (it "returns nil if its input is nil"
    (nil? (to-font nil)))
  (it "returns its input if its a font"
    (let [f (font)]
      (expect (= f (to-font f)))))
  (it "returns a new font if its input is a font spec"
    (let [f (to-font "ARIAL-ITALIC-14")]
      (expect (= Font/ITALIC (.getStyle f)))))
  (it "returns a new font if its input is a map"
    (let [f (to-font {:style :italic})]
      (expect (= Font/ITALIC (.getStyle f))))))

(describe default-font
  (it "retrieves a named from from the UIManager"
    (let [f (default-font "Label.font")
          expected (.getFont (javax.swing.UIManager/getDefaults) "Label.font")]
      (expect (not (nil? f)))
      (expect (= expected f)))))

Something went wrong with that request. Please try again.