v2 / vlib / v / vmod / encoder_test.v
67 lines · 60 sloc · 1.49 KB · c754b5e4ac9a9ed1bff9e2726b8888f7cef68e44
Raw
1import v.vmod
2
3const mf_no_deps = "Module {
4 name: 'V'
5 description: 'The V programming language.'
6 version: '0.4.10'
7 license: 'MIT'
8 repo_url: 'https://github.com/vlang/v'
9 dependencies: []
10}"
11
12fn test_encode_vmod_with_no_deps() {
13 mf := vmod.decode(mf_no_deps)!
14 assert vmod.encode(mf) == mf_no_deps
15}
16
17const mf_with_deps_1 = "Module {
18 name: 'V'
19 description: 'The V programming language.'
20 version: '0.4.10'
21 license: 'MIT'
22 repo_url: 'https://github.com/vlang/v'
23 dependencies: ['hello', 'world']
24}"
25
26const mf_with_deps_2 = 'Module {
27 name: \'V\'
28 description: "The V\' programming language."
29 version: \'0.4.10\'
30 license: \'MIT\'
31 repo_url: \'https://github.com/vlang/v\'
32 dependencies: [
33 \'hello\',
34 \'world\',
35 \'fdsfgarhrhregwegewgeage\',
36 \'geageaegeggegagaghjuktktytrrtrehitroorekfwepokooe\',
37 ]
38}'
39
40fn test_encode_vmod_with_multiple_deps() {
41 mf1 := vmod.decode(mf_with_deps_1)!
42 assert vmod.encode(mf1) == mf_with_deps_1
43 mf2 := vmod.decode(mf_with_deps_2)!
44 assert vmod.encode(mf2) == mf_with_deps_2
45}
46
47const mf_with_extra_fields = "Module {
48 name: 'V'
49 base_url: 'src'
50 description: 'The V programming language.'
51 version: '0.4.10'
52 license: 'MIT'
53 repo_url: 'https://github.com/vlang/v'
54 author: 'Bilbo Baggins'
55 dependencies: ['hello', 'world']
56 extra_a: ['a', 'b', 'c']
57 extra_b: [
58 'aaaaaaaaaaaaaaaaaaaaa',
59 'bbbbbbbbbbbbbbbbbbbbb',
60 'ccccccccccccccccccccc',
61 ]
62}"
63
64fn test_encode_vmod_with_extra_fields() {
65 mf := vmod.decode(mf_with_extra_fields)!
66 assert vmod.encode(mf) == mf_with_extra_fields
67}
68