summaryrefslogtreecommitdiff
path: root/tests/schemantic/literal.scm
blob: 486ca08bc015188f511dbd2a90b79fa865f8eba2 (plain)
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
; SPDX-FileCopyrightText: 2020 pukkamustard <pukkamustard@posteo.net>
;
; SPDX-License-Identifier: GPL-3.0-or-later

(define-module (tests schemantic literal)
  #:use-module (oop goops)
  #:use-module (schemantic rdf)
  #:use-module (schemantic xsd)
  #:use-module ((schemantic ns) #:select (xsd))

  #:use-module (srfi srfi-64))

(define-namespace ex "http://example.com/#")

(test-begin "generic literal")

(test-assert "generic literal is a literal"
  (literal?
   (make-generic-literal 1.9 #:datatype (ex "my-datatype"))))

(test-equal
    (ex "my-datatype")
  (literal-datatype
   (make-generic-literal 1.9 #:datatype (ex "my-datatype"))))

(test-end "generic literal")

(test-begin "xsd:string")

(test-assert "string is cast to a literal"
    (literal? (make-literal "hello")))

(test-assert "string is cast to a xsd:string"
  (is-a? (make-literal "hello") <xsd:string> ))

(test-equal "datatype is xsd:string"
  (xsd "string") (literal-datatype (make-literal "hello")))

(test-equal "value of xsd:string can be refed"
  "hello"
  (literal-value (make-literal "hello")))

(test-end "xsd:string")

(test-begin "xsd:integer")

(test-assert "integer is cast to a literal"
    (literal? (make-literal 42)))

(test-assert "integer is cast to a xsd:integer"
  (is-a? (make-literal 42) <xsd:integer>))

(test-equal "datatype is xsd:integer"
  (xsd "integer") (literal-datatype (make-literal 42)))

(test-equal "value of xsd:integer can be refed"
  42
  (literal-value (make-literal 42)))

(test-equal "lexical value is string representatoin"
  "42"
  (literal-lexical (make-literal 42)))

(test-end "xsd:integer")