forked from vadv/gopher-lua-libs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_test.go
92 lines (84 loc) · 1.84 KB
/
example_test.go
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// +build !windows,!plan9
package filepath
import (
"log"
inspect "github.com/alexjx/gopher-lua-libs/inspect"
lua "github.com/yuin/gopher-lua"
)
// filepath.ext(string)
func ExampleExt() {
state := lua.NewState()
Preload(state)
source := `
local filepath = require("filepath")
local result = filepath.ext("/var/tmp/file.name")
print(result)
`
if err := state.DoString(source); err != nil {
log.Fatal(err.Error())
}
// Output:
// .name
}
// filepath.basename(string)
func ExampleBasename() {
state := lua.NewState()
Preload(state)
source := `
local filepath = require("filepath")
local result = filepath.basename("/var/tmp/file.name")
print(result)
`
if err := state.DoString(source); err != nil {
log.Fatal(err.Error())
}
// Output:
// file.name
}
// filepath.basename(string)
func ExampleDir() {
state := lua.NewState()
Preload(state)
source := `
local filepath = require("filepath")
local result = filepath.dir("/var/tmp/file.name")
print(result)
`
if err := state.DoString(source); err != nil {
log.Fatal(err.Error())
}
// Output:
// /var/tmp
}
// filepath.basename(string)
func ExampleJoin() {
state := lua.NewState()
Preload(state)
source := `
local filepath = require("filepath")
local result = filepath.join("var", "tmp", "file.name")
print(result)
`
if err := state.DoString(source); err != nil {
log.Fatal(err.Error())
}
// Output:
// var/tmp/file.name
}
// filepath.glob(string)
func ExampleGlob() {
state := lua.NewState()
Preload(state)
inspect.Preload(state)
source := `
local filepath = require("filepath")
local inspect = require("inspect")
local result = filepath.glob("./*/*.lua")
print(inspect(result, {newline="", indent=""}))
`
if err := state.DoString(source); err != nil {
log.Fatal(err.Error())
}
// Output:
// { "test/test_api.lua" }
}