11package lua_global
22
3- import "testing"
3+ import (
4+ "fmt"
5+ "testing"
46
5- var githubScript = `print("------------github------------")
7+ lua "github.com/yuin/gopher-lua"
8+ )
69
10+ var githubScript = `
711function tagFilter(str)
8- local s = regexpFindString ("v\\d+(.\\d+){2}", str)
12+ local s = vmrRegexpFindString ("v\\d+(.\\d+){2}", str)
913 if s ~= "" then
1014 return true
1115 end
1216 return false
1317end
1418
1519function versionParser(str)
16- local s = regexpFindString ("v(\\d+)(.\\d+){2}", str)
17- s = trimPrefix (s, "v")
20+ local s = vmrRegexpFindString ("v(\\d+)(.\\d+){2}", str)
21+ s = vmrTrimPrefix (s, "v")
1822 return s
1923end
2024
2125function fileFilter(str)
22- if contains (str, "profile") then
26+ if vmrContains (str, "profile") then
2327 return false
2428 end
25- if contains (str, "baseline") then
29+ if vmrContains (str, "baseline") then
2630 return false
2731 end
28- if hasSuffix (str, ".txt") then
32+ if vmrHasSuffix (str, ".txt") then
2933 return false
3034 end
31- if hasSuffix (str, ".txt.asc") then
35+ if vmrHasSuffix (str, ".txt.asc") then
3236 return false
3337 end
34- if hasSuffix (str, "musl.zip") then
38+ if vmrHasSuffix (str, "musl.zip") then
3539 return false
3640 end
3741 return true
3842end
3943
4044function archParser(str)
41- if contains (str, "-x64") then
45+ if vmrContains (str, "-x64") then
4246 return "amd64"
4347 end
44- if contains (str, "-aarch64") then
48+ if vmrContains (str, "-aarch64") then
4549 return "arm64"
4650 end
4751 return ""
4852end
4953
5054function osParser(str)
51- if contains (str, "linux") then
55+ if vmrContains (str, "linux") then
5256 return "linux"
5357 end
54- if contains (str, "darwin") then
58+ if vmrContains (str, "darwin") then
5559 return "darwin"
5660 end
57- if contains (str, "windows") then
61+ if vmrContains (str, "windows") then
5862 return "windows"
5963 end
6064 return ""
@@ -64,16 +68,25 @@ function installerGetter(str)
6468 return "unarchiver"
6569end
6670
67- local result = getGithubRelease ("oven-sh/bun", tagFilter, versionParser, fileFilter, archParser, osParser, installerGetter)
71+ result = vmrGetGithubRelease ("oven-sh/bun", tagFilter, versionParser, fileFilter, archParser, osParser, installerGetter)
6872print(result)
6973`
7074
7175func TestGithub (t * testing.T ) {
72- ll := NewLua ()
73- defer ll .Close ()
74- L := ll .GetLState ()
75-
76- if err := L .DoString (githubScript ); err != nil {
76+ l , err := ExecuteLuaScriptL (githubScript )
77+ if err != nil {
7778 t .Error (err )
79+ } else {
80+ v := l .GetGlobal ("result" )
81+
82+ if v .Type () == lua .LTUserData {
83+ ud := v .(* lua.LUserData )
84+ if ud == nil {
85+ return
86+ }
87+ if vl , ok := ud .Value .(VersionList ); ok {
88+ _ , _ = fmt .Printf ("version list: %+v\n " , vl )
89+ }
90+ }
7891 }
7992}
0 commit comments