summaryrefslogtreecommitdiffstats
path: root/tcllib/modules/doctools2toc/import_json.test
blob: 3bf27f9b5c9de2f90e2007c21385c2d8743e7e31 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# -*- tcl -*-
# toc_import_json.test:  tests for the doctools::toc::import::json package/plugin.
#
# Copyright (c) 2009 by Andreas Kupries <andreas_kupries@users.sourceforge.net>
# All rights reserved.
#
# RCS: @(#) $Id: import_json.test,v 1.1 2009/04/18 21:14:19 andreas_kupries Exp $

# -------------------------------------------------------------------------

source [file join \
	[file dirname [file dirname [file join [pwd] [info script]]]] \
	devtools testutilities.tcl]

testsNeedTcl     8.4
testsNeedTcltest 2.0

support {
    use fileutil/fileutil.tcl  fileutil
    use struct/list.tcl        struct::list

    # Copy of code from import_json.tcl, to define dict support
    # even where dict is not really present on the system.

    if {[package vcompare [package present Tcl] 8.5] < 0} {
	if {[catch {
	    package require dict
	}]} {
	    # Create a pure Tcl implementation of the dict methods
	    # required by json, and fake the presence of the dict package.
	    proc dict {cmd args} { return [uplevel 1 [linsert $args 0 dict/$cmd]] }
	    proc dict/create {} { return {} }
	    proc dict/set {var key val} {
		upvar 1 $var a
		array set x $a
		set x($key) $val
		set a [array get x]
		return
	    }
	    package provide dict 1
	}
    }
    use json/json.tcl          json

    useLocal structure.tcl doctools::toc::structure

    #msgcat::mclocale C
}
testing {
    package provide doctools::toc::import::plugin 1
    # The above fakes plugin environment. Well, not completely. By
    # leaving out a definition for the 'include' alias the plugin is
    # signaled that there is no need to overwrite the GetFile command
    # of doctools::toc::parse with a version calling out to the plugin
    # manager, i.e. that it can still use the regular file operations.

    useLocal import_json.tcl doctools::toc::import::json
}

source [tcllibPath doctools2base/tests/common]
set mytestdir tests/data

# -------------------------------------------------------------------------

# General set of error cases regarding the number of arguments.

test doctools-toc-import-json-1.0 {import, wrong#args} -body {
    import
} -returnCodes error -result {wrong # args: should be "import text configuration"}

test doctools-toc-import-json-1.1 {import, wrong#args} -body {
    import T
} -returnCodes error -result {wrong # args: should be "import text configuration"}

test doctools-toc-import-json-1.2 {import, wrong#args} -body {
    import T C XXX
} -returnCodes error -result {wrong # args: should be "import text configuration"}

# toc_import_json tests, numbering starts at 2
# -------------------------------------------------------------------------

# We are checking that the various forms of json markup, as can be
# generated by doctools::toc(::export(::json)) are valid input to the
# json parser.
#
# section {} holds the non-canonical input we have to accept and make
# canonical to higher layers.

foreach {k section} {
    0 {}
    1 -ultracompact
    2 -indented
    3 -indalign
} {
    TestFilesProcess $mytestdir ok json$section serial-print -> n label input data expected {
	test doctools-toc-import-json-2.$k.$n "doctools::toc::import::json, $label$section, ok" -body {
	    doctools::toc::structure print [import $data {}]
	} -result $expected
    }
}

# -------------------------------------------------------------------------

# We test the error messages and codes thrown by the parser for a
# variety of failure possibilities.

TestFilesProcess $mytestdir fail json json-emsg -> n label input data expected {
    test doctools-toc-import-json-3.$n "doctools::toc::import::json, $label, error message" -body {
	import $data {}
    } -returnCodes error -result $expected
}

#----------------------------------------------------------------------
testsuiteCleanup
return