| 1 | import v.vmod |
| 2 | |
| 3 | const quote = '\x22' |
| 4 | |
| 5 | const apos = '\x27' |
| 6 | |
| 7 | fn test_ok() { |
| 8 | ok_source := "Module { |
| 9 | name: 'V' |
| 10 | description: 'The V programming language.' |
| 11 | version: '0.7.7' |
| 12 | license: 'MIT' |
| 13 | repo_url: 'https://github.com/vlang/v' |
| 14 | dependencies: [] |
| 15 | }" |
| 16 | for s in [ok_source, ok_source.replace(apos, quote), ok_source.replace('\n', '\r\n'), |
| 17 | ok_source.replace('\n', '\r\n '), ok_source.replace('\n', '\n ')] { |
| 18 | content := vmod.decode(s)! |
| 19 | assert content.name == 'V' |
| 20 | assert content.base_url == '' |
| 21 | assert content.description == 'The V programming language.' |
| 22 | assert content.version == '0.7.7' |
| 23 | assert content.license == 'MIT' |
| 24 | assert content.repo_url == 'https://github.com/vlang/v' |
| 25 | assert content.dependencies == [] |
| 26 | assert content.unknown == {} |
| 27 | } |
| 28 | e := vmod.decode('Module{}')! |
| 29 | assert e.name == '' |
| 30 | assert e.base_url == '' |
| 31 | assert e.description == '' |
| 32 | assert e.version == '' |
| 33 | assert e.license == '' |
| 34 | assert e.repo_url == '' |
| 35 | assert e.dependencies == [] |
| 36 | assert e.unknown == {} |
| 37 | } |
| 38 | |
| 39 | fn test_invalid_start() { |
| 40 | vmod.decode('\n\nXYZ') or { |
| 41 | assert err.msg() == 'vmod: v.mod files should start with Module, at line 3' |
| 42 | return |
| 43 | } |
| 44 | assert false |
| 45 | } |
| 46 | |
| 47 | fn test_base_url() { |
| 48 | content := vmod.decode("Module {\n\tname: 'V'\n\tbase_url: 'source'\n}")! |
| 49 | assert content.base_url == 'source' |
| 50 | } |
| 51 | |
| 52 | fn test_invalid_end() { |
| 53 | vmod.decode('\nModule{\n \nname: ${quote}zzzz}') or { |
| 54 | assert err.msg() == 'vmod: invalid token ${quote}eof${quote}, at line 4' |
| 55 | return |
| 56 | } |
| 57 | assert false |
| 58 | } |
| 59 | |