coded".split(/<(\/)?([^<>]+)>/)`, "A,,B,bold,/,B,and,,CODE,coded,/,CODE,")
test(`_.length`, 13)
test(`_[1] === undefined`, true)
test(`_[12] === ""`, true)
test(`
var abc = new String("one-1 two-2 three-3");
var def = abc.split(new RegExp);
[ def.constructor === Array, abc.length, def.length, def.join('') ];
`, "true,19,19,one-1 two-2 three-3")
})
}
func BenchmarkString_splitWithString(b *testing.B) {
vm := New()
err := vm.Set("data", "Lorem ipsum dolor sit amet, blandit nec elit. Ridiculous tortor wisi fusce vivamus")
require.NoError(b, err)
s, err := vm.Compile("test.js", `data.split(" ")`)
require.NoError(b, err)
for i := 0; i < b.N; i++ {
_, err = vm.Run(s)
require.NoError(b, err)
}
}
func BenchmarkString_splitWithRegex(b *testing.B) {
vm := New()
err := vm.Set("data", "Lorem ipsum dolor sit amet, blandit nec elit. Ridiculous tortor wisi fusce vivamus")
require.NoError(b, err)
s, err := vm.Compile("test.js", `data.split(/ /)`)
require.NoError(b, err)
for i := 0; i < b.N; i++ {
_, err = vm.Run(s)
require.NoError(b, err)
}
}
func TestString_slice(t *testing.T) {
tt(t, func() {
test, _ := test()
test(`"abc".slice()`, "abc")
test(`"abc".slice(0)`, "abc")
test(`"abc".slice(0,11)`, "abc")
test(`"abc".slice(0,-1)`, "ab")
test(`"abc".slice(-1,11)`, "c")
test(`abc = "abc"; abc.slice(abc.length+1, 0)`, "")
})
}
func TestString_length(t *testing.T) {
tt(t, func() {
test, _ := test()
test(`"abc".length`, 3)
test(`"uñiçode".length`, 7)
test(`"😋".length`, 2)
})
}
func TestString_slice_unicode(t *testing.T) {
tt(t, func() {
test, _ := test()
test(`"uñiçode".slice()`, "uñiçode")
test(`"uñiçode".slice(0)`, "uñiçode")
test(`"uñiçode".slice(0,11)`, "uñiçode")
test(`"uñiçode".slice(0,-1)`, "uñiçod")
test(`"uñiçode".slice(-1,11)`, "e")
test(`"发送 213123".slice(0,2)`, "发送")
})
}
func TestString_substring_unicode(t *testing.T) {
tt(t, func() {
test, _ := test()
test(`"uñiçode".substring()`, "uñiçode")
test(`"uñiçode".substring(0)`, "uñiçode")
test(`"uñiçode".substring(0,11)`, "uñiçode")
test(`"uñiçode".substring(11,0)`, "uñiçode")
test(`"uñiçode".substring(0,-1)`, "")
test(`"uñiçode".substring(-1,11)`, "uñiçode")
test(`"uñiçode".substring(1)`, "ñiçode")
test(`"uñiçode".substring(Infinity, Infinity)`, "")
})
}
func TestString_substring(t *testing.T) {
tt(t, func() {
test, _ := test()
test(`"abc".substring()`, "abc")
test(`"abc".substring(0)`, "abc")
test(`"abc".substring(0,11)`, "abc")
test(`"abc".substring(11,0)`, "abc")
test(`"abc".substring(0,-1)`, "")
test(`"abc".substring(-1,11)`, "abc")
test(`"abc".substring(11,1)`, "bc")
test(`"abc".substring(1)`, "bc")
test(`"abc".substring(Infinity, Infinity)`, "")
})
}
func TestString_toCase(t *testing.T) {
tt(t, func() {
test, _ := test()
test(`"abc".toLowerCase()`, "abc")
test(`"ABC".toLowerCase()`, "abc")
test(`"abc".toLocaleLowerCase()`, "abc")
test(`"ABC".toLocaleLowerCase()`, "abc")
test(`"abc".toUpperCase()`, "ABC")
test(`"ABC".toUpperCase()`, "ABC")
test(`"abc".toLocaleUpperCase()`, "ABC")
test(`"ABC".toLocaleUpperCase()`, "ABC")
})
}
func Test_floatToString(t *testing.T) {
tt(t, func() {
test, _ := test()
test(`String(-1234567890)`, "-1234567890")
test(`-+String(-(-1234567890))`, -1234567890)
test(`String(-1e128)`, "-1e+128")
test(`String(0.12345)`, "0.12345")
test(`String(-0.00000012345)`, "-1.2345e-7")
test(`String(0.0000012345)`, "0.0000012345")
test(`String(1000000000000000000000)`, "1e+21")
test(`String(1e21)`, "1e+21")
test(`String(1E21)`, "1e+21")
test(`String(-1000000000000000000000)`, "-1e+21")
test(`String(-1e21)`, "-1e+21")
test(`String(-1E21)`, "-1e+21")
test(`String(0.0000001)`, "1e-7")
test(`String(1e-7)`, "1e-7")
test(`String(1E-7)`, "1e-7")
test(`String(-0.0000001)`, "-1e-7")
test(`String(-1e-7)`, "-1e-7")
test(`String(-1E-7)`, "-1e-7")
})
}
func TestString_indexing(t *testing.T) {
tt(t, func() {
test, _ := test()
// Actually a test of stringToArrayIndex, under the hood.
test(`
abc = new String("abc");
index = Math.pow(2, 32);
[ abc.length, abc[index], abc[index+1], abc[index+2], abc[index+3] ];
`, "3,,,,")
})
}
func TestString_trim(t *testing.T) {
tt(t, func() {
test, _ := test()
test(`' \n abc \t \n'.trim();`, "abc")
test(`" abc\u000B".trim()`, "abc")
test(`"abc ".trim()`, "abc")
test(`
var a = "\u180Eabc \u000B "
var b = a.trim()
a.length + b.length
`, 10)
})
}
func TestString_trimLeft(t *testing.T) {
tt(t, func() {
test, _ := test()
test(`" abc\u000B".trimLeft()`, "abc\u000B")
test(`"abc ".trimLeft()`, "abc ")
test(`
var a = "\u180Eabc \u000B "
var b = a.trimLeft()
a.length + b.length
`, 13)
})
}
func TestString_trimRight(t *testing.T) {
tt(t, func() {
test, _ := test()
test(`" abc\u000B".trimRight()`, " abc")
test(`" abc ".trimRight()`, " abc")
test(`
var a = "\u180Eabc \u000B "
var b = a.trimRight()
a.length + b.length
`, 11)
})
}
func TestString_localeCompare(t *testing.T) {
tt(t, func() {
test, _ := test()
test(`'a'.localeCompare('c');`, -1)
test(`'c'.localeCompare('a');`, 1)
test(`'a'.localeCompare('a');`, 0)
})
}
func TestString_startsWith(t *testing.T) {
tt(t, func() {
test, _ := test()
test(`'a'.startsWith('c');`, false)
test(`'aa'.startsWith('a');`, true)
})
}
func TestString_trimStart(t *testing.T) {
tt(t, func() {
test, _ := test()
test(`" abc\u000B".trimStart()`, "abc\u000B")
test(`"abc ".trimStart()`, "abc ")
test(`
var a = "\u180Eabc \u000B "
var b = a.trimStart()
a.length + b.length
`, 13)
})
}
func TestString_trimEnd(t *testing.T) {
tt(t, func() {
test, _ := test()
test(`" abc\u000B".trimEnd()`, " abc")
test(`" abc ".trimEnd()`, " abc")
test(`
var a = "\u180Eabc \u000B "
var b = a.trimEnd()
a.length + b.length
`, 11)
})
}
================================================
FILE: terst/terst.go
================================================
// This file was AUTOMATICALLY GENERATED by terst-import (smuggol) from github.com/robertkrimen/terst
/*
Package terst is a terse (terst = test + terse), easy-to-use testing library for Go.
terst is compatible with (and works via) the standard testing package: http://golang.org/pkg/testing
var is = terst.Is
func Test(t *testing.T) {
terst.Terst(t, func() {
is("abc", "abc")
is(1, ">", 0)
var abc []int
is(abc, nil)
}
}
Do not import terst directly, instead use `terst-import` to copy it into your testing environment:
https://github.com/robertkrimen/terst/tree/master/terst-import
$ go get github.com/robertkrimen/terst/terst-import
$ terst-import
*/
package terst
import (
"bytes"
"errors"
"fmt"
"math/big"
"reflect"
"regexp"
goruntime "runtime"
"strings"
"sync"
"testing"
"time"
)
// Is compares two values (got & expect) and returns true if the comparison is true,
// false otherwise. In addition, if the comparison is false, Is will report the error
// in a manner similar to testing.T.Error(...). Is also takes an optional argument,
// a comparator, that changes how the comparison is made. The following
// comparators are available:
//
// == # got == expect (default)
// != # got != expect
//
// > # got > expect (float32, uint, uint16, int, int64, ...)
// >= # got >= expect
// < # got < expect
// <= # got <= expect
//
// =~ # regexp.MustCompile(expect).Match{String}(got)
// !~ # !regexp.MustCompile(expect).Match{String}(got)
//
// Basic usage with the default comparator (==):
//
// Is(\u2028<%= "\\u2028\\u2029" %>\u2029
')()`, "\u2028\u2028\u2029\u2029
") }) } // TODO Test: typeof An argument reference // TODO Test: abc = {}; abc == Object(abc) ================================================ FILE: underscore_utility_test.go ================================================ package otto import ( "testing" ) // #750 - Return _ instance. func Test_underscore_utility_0(t *testing.T) { tt(t, func() { test := underscoreTest() test(` test("#750 - Return _ instance.", 2, function() { var instance = _([]); ok(_(instance) === instance); ok(new _(instance) === instance); }); `) }) } // identity. func Test_underscore_utility_1(t *testing.T) { tt(t, func() { test := underscoreTest() test(` test("identity", function() { var moe = {name : 'moe'}; equal(_.identity(moe), moe, 'moe is the same as his identity'); }); `) }) } // random. func Test_underscore_utility_2(t *testing.T) { tt(t, func() { test := underscoreTest() test(` test("random", function() { var array = _.range(1000); var min = Math.pow(2, 31); var max = Math.pow(2, 62); ok(_.every(array, function() { return _.random(min, max) >= min; }), "should produce a random number greater than or equal to the minimum number"); ok(_.some(array, function() { return _.random(Number.MAX_VALUE) > 0; }), "should produce a random number when passedJust some text. Hey, I know this is silly but it aids consistency.
Just some text. Hey, I know this is silly but it aids consistency.