MCPcopy Create free account
hub / github.com/crossoverJie/gscript / TestArraySlice3

Function TestArraySlice3

byte_test.go:113–148  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

111 NewCompiler().Compiler(script)
112}
113func TestArraySlice3(t *testing.T) {
114 script := `
115string S = "abcdefx";
116string T = "def";
117int myIndex(string S,string T,int pos) {
118 int i = pos;
119 int j = 0;
120 byte[] s = toByteArray(S);
121 byte[] t = toByteArray(T);
122
123 int slen = len(s);
124 int tlen = len(t);
125 for(i <= slen && j <= tlen) {
126 byte si = s[i];
127 byte sj = s[j];
128 if (si == sj) {
129 i = i+1;
130 j = j+1;
131 }else{
132 i = i - j + 1;
133 j = 0;
134 }
135 }
136 if (j == tlen) {
137 return i - tlen;
138 } else {
139 return slen-i;
140 }
141 return 0;
142}
143
144int res = myIndex(S,T,0);
145println(res);
146`
147 NewCompiler().Compiler(script)
148}
149func TestStringBuilder2(t *testing.T) {
150
151 var x strings.Builder

Callers

nothing calls this directly

Calls 2

NewCompilerFunction · 0.85
CompilerMethod · 0.80

Tested by

no test coverage detected