|
0 |
require 'spec.test_util'
|
|
1 |
package.loaded['mmm.mmmfs.conversion'] = {}
|
|
2 |
import Key from require 'mmm.mmmfs.fileder'
|
|
3 |
|
|
4 |
nt = (name, type) -> :name, :type
|
|
5 |
|
|
6 |
describe "Key", ->
|
|
7 |
it "can be instantiated from a string", ->
|
|
8 |
assert.are.same (nt '', 'type/only'), Key 'type/only'
|
|
9 |
assert.are.same (nt '', 'type/only'), Key ':type/only'
|
|
10 |
assert.are.same (nt '', 'the/type'), Key ' the/type'
|
|
11 |
assert.are.same (nt '', 'the/type'), Key ': the/type'
|
|
12 |
assert.are.same (nt '', 'URL -> long/type -> some/type'), Key 'URL -> long/type -> some/type'
|
|
13 |
|
|
14 |
assert.are.same (nt 'facet_name', 'some/type'), Key 'facet_name: some/type'
|
|
15 |
assert.are.same (nt 'spacious_name', 'and/type'), Key 'spacious_name: and/type'
|
|
16 |
assert.are.same (nt 'name', 'URL -> long/type -> some/type'), Key 'name: URL -> long/type -> some/type'
|
|
17 |
|
|
18 |
it "can be instantiated from two strings", ->
|
|
19 |
assert.are.same (nt '', 'type/only'), Key '', 'type/only'
|
|
20 |
assert.are.same (nt '', 'type/only'), Key nil, 'type/only'
|
|
21 |
assert.are.same (nt 'facet_name', 'some/type'), Key 'facet_name', 'some/type'
|
|
22 |
|
|
23 |
assert.are.same (nt 'name', 'URL -> long/type -> some/type'), Key 'name', 'URL -> long/type -> some/type'
|
|
24 |
assert.are.same (nt '', 'URL -> long/type -> some/type'), Key '', 'URL -> long/type -> some/type'
|
|
25 |
|
|
26 |
assert.are.same (nt 'spacious_name', ' and/type'), Key 'spacious_name', ' and/type'
|
|
27 |
assert.are.same (nt '', ' the/type'), Key nil, ' the/type'
|
|
28 |
|
|
29 |
it "can be instantiated from a table or instance", ->
|
|
30 |
assert.are.same (nt '', 'type/only'), Key Key '', 'type/only'
|
|
31 |
assert.are.same (nt '', 'type/only'), Key nt '', 'type/only'
|
|
32 |
assert.are.same (nt '', 'type/only'), Key nt nil, 'type/only'
|
|
33 |
|
|
34 |
assert.are.same (nt 'facet', 'the/type+extra'), Key Key 'facet', 'the/type+extra'
|
|
35 |
assert.are.same (nt 'facet', 'the/type+extra'), Key nt 'facet', 'the/type+extra'
|
|
36 |
|
|
37 |
it "throws an error otherwise", ->
|
|
38 |
assert.has_error -> Key!
|
|
39 |
assert.has_error -> Key true
|
|
40 |
assert.has_error -> Key true, false
|
|
41 |
assert.has_error -> Key 4
|
|
42 |
assert.has_error -> Key 4, 5
|
|
43 |
assert.has_error -> Key {}
|
|
44 |
assert.has_error -> Key type: true
|
|
45 |
|
|
46 |
it "tostring formats the key", ->
|
|
47 |
assert.is.equal 'type/only', tostring Key 'type/only'
|
|
48 |
assert.is.equal 'type/only', tostring Key '', 'type/only'
|
|
49 |
assert.is.equal 'type/only', tostring Key ": type/only"
|
|
50 |
|
|
51 |
assert.is.equal 'facet: and/type+extra', tostring Key 'facet: and/type+extra'
|
|
52 |
assert.is.equal 'facet: and/type+extra', tostring Key 'facet', 'and/type+extra'
|
|
53 |
assert.is.equal 'facet: and/type+extra', tostring Key 'facet: and/type+extra'
|
|
54 |
|
|
55 |
assert.is.equal 'facet: and -> long -> type', tostring Key 'facet: and -> long -> type'
|
|
56 |
assert.is.equal 'facet: and -> long -> type', tostring Key 'facet', 'and -> long -> type'
|
|
57 |
assert.is.equal 'facet: and -> long -> type', tostring Key 'facet: and -> long -> type'
|