aboutsummaryrefslogtreecommitdiff
path: root/v_windows/v/vlib/v/tests/vmod_parser_test.v
blob: 10f48141c8a56368a3478ddd18348a079ae596c0 (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
import v.vmod
import os

fn test_from_file() {
	os.chdir(os.dir(os.getenv('VEXE'))) or {}
	data := vmod.from_file('./v.mod') or { panic(err) }
	assert data.name == 'V'
	assert data.description == 'The V programming language.'
	// assert data.version == '0.2.1'
	assert data.version.contains('.')
	assert data.version.starts_with('0.')
	assert data.dependencies.len == 0
}

fn test_decode() {
	content := "
	  Module {
		name: 'foobar',
		description: 'Just a sample module'
		version: '0.2.0',
		repo_url: 'https://gitlab.com',
		author: 'Fooz Bar',
		license: 'GPL-2.0',
		dependencies: ['hello'],
		test: 'foo'
	  }
	"
	data := vmod.decode(content) or {
		println(err)
		exit(1)
	}
	assert data.name == 'foobar'
	assert data.version == '0.2.0'
	assert data.description == 'Just a sample module'
	assert data.repo_url == 'https://gitlab.com'
	assert data.author == 'Fooz Bar'
	assert data.license == 'GPL-2.0'
	assert data.dependencies[0] == 'hello'
	assert data.unknown['test'][0] == 'foo'
	vmod.decode('') or {
		assert err.msg == 'vmod: no content.'
		exit(0)
	}
}

fn test_decode_with_comptime_vmod_file() {
	mod := vmod.decode(@VMOD_FILE) or { panic('Error decoding v.mod') }
	assert mod.name == 'V'
	assert mod.repo_url == 'https://github.com/vlang/v'
	assert mod.license == 'MIT'
}