Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v.vmod: make the v.mod parser more robust, show line numbers in error…
…s, add tests
- Loading branch information
Showing
3 changed files
with
74 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import v.vmod | ||
|
||
const quote = '\x22' | ||
|
||
const apos = '\x27' | ||
|
||
fn test_ok() ? { | ||
ok_source := "Module { | ||
name: 'V' | ||
description: 'The V programming language.' | ||
version: '0.2.4' | ||
license: 'MIT' | ||
repo_url: 'https://github.com/vlang/v' | ||
dependencies: [] | ||
}" | ||
for s in [ok_source, ok_source.replace(apos, quote), ok_source.replace('\n', '\r\n'), | ||
ok_source.replace('\n', '\r\n '), ok_source.replace('\n', '\n ')] { | ||
content := vmod.decode(s) ? | ||
assert content.name == 'V' | ||
assert content.description == 'The V programming language.' | ||
assert content.version == '0.2.4' | ||
assert content.license == 'MIT' | ||
assert content.repo_url == 'https://github.com/vlang/v' | ||
assert content.dependencies == [] | ||
assert content.unknown == {} | ||
} | ||
e := vmod.decode('Module{}') ? | ||
assert e.name == '' | ||
assert e.description == '' | ||
assert e.version == '' | ||
assert e.license == '' | ||
assert e.repo_url == '' | ||
assert e.dependencies == [] | ||
assert e.unknown == {} | ||
} | ||
|
||
fn test_invalid_start() ? { | ||
vmod.decode('\n\nXYZ') or { | ||
assert err.msg() == 'vmod: v.mod files should start with Module, at line 3' | ||
return | ||
} | ||
assert false | ||
} | ||
|
||
fn test_invalid_end() ? { | ||
vmod.decode('\nModule{\n \nname: ${quote}zzzz}') or { | ||
assert err.msg() == 'vmod: invalid token ${quote}eof$quote, at line 4' | ||
return | ||
} | ||
assert false | ||
} |