• Home
  • Raw
  • Download

Lines Matching +full:thread +full:- +full:1 +full:- +full:4

2 // Use of this source code is governed by a BSD-style
27 // A test may enable non-standard options by containing (e.g.) "option:recursion".
48 thread := new(starlark.Thread)
51 {`-1`, `-1`},
53 {`1+2`, `3`},
57 {`[1]`, `[1]`},
58 {`[1,]`, `[1]`},
59 {`[1, 2]`, `[1, 2]`},
60 {`[2 * x for x in [1, 2, 3]]`, `[2, 4, 6]`},
61 {`[2 * x for x in [1, 2, 3] if x > 1]`, `[4, 6]`},
62 {`[(x, y) for x in [1, 2] for y in [3, 4]]`,
63 `[(1, 3), (1, 4), (2, 3), (2, 4)]`},
64 {`[(x, y) for x in [1, 2] if x == 2 for y in [3, 4]]`,
65 `[(2, 3), (2, 4)]`},
68 {`(1)`, `1`},
69 {`(1,)`, `(1,)`},
70 {`(1, 2)`, `(1, 2)`},
71 {`(1, 2, 3, 4, 5)`, `(1, 2, 3, 4, 5)`},
72 {`1, 2`, `(1, 2)`},
75 {`{"a": 1}`, `{"a": 1}`},
76 {`{"a": 1,}`, `{"a": 1}`},
79 {`1 if 3 > 2 else 0`, `1`},
80 {`1 if "foo" else 0`, `1`},
81 {`1 if "" else 0`, `0`},
85 {`["a", "b"][1]`, `"b"`},
87 {`("a", "b")[1]`, `"b"`},
89 {`"aΩb"[1]`, `"\xce"`},
91 {`{"a": 1}["a"]`, `1`},
92 {`{"a": 1}["b"]`, `key "b" not in dict`},
94 {`{"a": 1}[[]]`, `unhashable type: list`},
95 {`[x for x in range(3)]`, "[0, 1, 2]"},
98 if v, err := starlark.Eval(thread, "<expr>", test.src, nil); err != nil {
112 thread := &starlark.Thread{Load: load}
113 starlarktest.SetReporter(thread, t)
144 _, err := starlark.ExecFile(thread, filename, chunk.Source, predeclared)
177 func (t fib) Iterate() starlark.Iterator { return &fibIterator{0, 1} }
189 func load(thread *starlark.Thread, module string) (starlark.StringDict, error) { argument
198 filename := filepath.Join(filepath.Dir(thread.CallFrame(0).Pos.Filename()), module)
199 return starlark.ExecFile(thread, filename, nil, nil)
202 func newHasFields(thread *starlark.Thread, b *starlark.Builtin, args starlark.Tuple, kwargs []starl… argument
209 // hasfields is a test-only implementation of HasAttrs.
295 thread := new(starlark.Thread)
296 globals, err := starlark.ExecFile(thread, filename, src, nil)
305 {`a(1)`, `function a accepts no arguments (1 given)`},
309 {`b(1)`, `function b missing 1 argument (b)`},
310 {`b(a=1)`, `function b missing 1 argument (b)`},
311 {`b(b=1)`, `function b missing 1 argument (a)`},
312 {`b(1, 2)`, `(1, 2)`},
314 {`b(1, 2, 3)`, `function b accepts 2 positional arguments (3 given)`},
315 {`b(1, b=2)`, `(1, 2)`},
316 {`b(1, a=2)`, `function b got multiple values for parameter "a"`},
317 {`b(1, x=2)`, `function b got an unexpected keyword argument "x"`},
318 {`b(a=1, b=2)`, `(1, 2)`},
319 {`b(b=1, a=2)`, `(2, 1)`},
320 {`b(b=1, a=2, x=1)`, `function b got an unexpected keyword argument "x"`},
321 {`b(x=1, b=1, a=2)`, `function b got an unexpected keyword argument "x"`},
324 {`c()`, `function c missing 1 argument (a)`},
325 {`c(1)`, `(1, 42)`},
326 {`c(1, 2)`, `(1, 2)`},
327 {`c(1, 2, 3)`, `function c accepts at most 2 positional arguments (3 given)`},
328 {`c(1, b=2)`, `(1, 2)`},
329 {`c(1, a=2)`, `function c got multiple values for parameter "a"`},
330 {`c(a=1, b=2)`, `(1, 2)`},
331 {`c(b=1, a=2)`, `(2, 1)`},
335 {`d(1)`, `(1,)`},
336 {`d(1, 2)`, `(1, 2)`},
337 {`d(1, 2, k=3)`, `function d got an unexpected keyword argument "k"`},
342 {`e(1)`, `function e accepts 0 positional arguments (1 given)`},
343 {`e(k=1)`, `{"k": 1}`},
347 {`f()`, `function f missing 1 argument (a)`},
350 {`f(0, 1)`, `(0, 1, (), {})`},
351 {`f(0, 1, 2)`, `(0, 1, (2,), {})`},
352 {`f(0, 1, 2, 3)`, `(0, 1, (2, 3), {})`},
354 {`f(0, b=1)`, `(0, 1, (), {})`},
355 {`f(0, a=1)`, `function f got multiple values for parameter "a"`},
356 {`f(0, b=1, c=2)`, `(0, 1, (), {"c": 2})`},
359 {`g()`, `function g missing 1 argument (a)`},
361 {`g(0, 1)`, `(0, 1, (), 123, {})`},
362 {`g(0, 1, 2)`, `(0, 1, (2,), 123, {})`},
363 {`g(0, 1, 2, 3)`, `(0, 1, (2, 3), 123, {})`},
365 {`g(0, b=1)`, `(0, 1, (), 123, {})`},
366 {`g(0, a=1)`, `function g got multiple values for parameter "a"`},
367 {`g(0, b=1, c=2, d=3)`, `(0, 1, (), 2, {"d": 3})`},
370 {`h()`, `function h missing 1 argument (a)`},
372 {`h(0, 1)`, `(0, 1, 123, {})`},
373 {`h(0, 1, 2)`, `function h accepts at most 2 positional arguments (3 given)`},
375 {`h(0, b=1)`, `(0, 1, 123, {})`},
376 {`h(0, a=1)`, `function h got multiple values for parameter "a"`},
377 {`h(0, b=1, c=2)`, `(0, 1, 2, {})`},
378 {`h(0, b=1, d=2)`, `(0, 1, 123, {"d": 2})`},
379 {`h(0, b=1, c=2, d=3)`, `(0, 1, 2, {"d": 3})`},
384 {`i(0, 1)`, `function i missing 2 arguments (c, e)`},
385 {`i(0, 1, 2)`, `function i accepts at most 2 positional arguments (3 given)`},
386 {`i(0, 1, e=2)`, `function i missing 1 argument (c)`},
387 {`i(0, 1, 2, 3)`, `function i accepts at most 2 positional arguments (4 given)`},
389 {`i(0, b=1)`, `function i missing 2 arguments (c, e)`},
390 {`i(0, a=1)`, `function i got multiple values for parameter "a"`},
391 {`i(0, b=1, c=2)`, `function i missing 1 argument (e)`},
392 {`i(0, b=1, d=2)`, `function i missing 2 arguments (c, e)`},
393 {`i(0, b=1, c=2, d=3)`, `function i missing 1 argument (e)`},
394 {`i(0, b=1, c=2, d=3, e=4)`, `(0, 1, 2, 3, 4, {})`},
395 {`i(0, 1, b=1, c=2, d=3, e=4)`, `function i got multiple values for parameter "b"`},
400 {`j(0, 1)`, `function j missing 2 arguments (c, e)`},
401 {`j(0, 1, 2)`, `function j missing 2 arguments (c, e)`},
402 {`j(0, 1, e=2)`, `function j missing 1 argument (c)`},
403 {`j(0, 1, 2, 3)`, `function j missing 2 arguments (c, e)`},
405 {`j(0, b=1)`, `function j missing 2 arguments (c, e)`},
406 {`j(0, a=1)`, `function j got multiple values for parameter "a"`},
407 {`j(0, b=1, c=2)`, `function j missing 1 argument (e)`},
408 {`j(0, b=1, d=2)`, `function j missing 2 arguments (c, e)`},
409 {`j(0, b=1, c=2, d=3)`, `function j missing 1 argument (e)`},
410 {`j(0, b=1, c=2, d=3, e=4)`, `(0, 1, (), 2, 3, 4, {})`},
411 {`j(0, 1, b=1, c=2, d=3, e=4)`, `function j got multiple values for parameter "b"`},
412 {`j(0, 1, 2, c=3, e=4)`, `(0, 1, (2,), 3, 123, 4, {})`},
415 if v, err := starlark.Eval(thread, "<expr>", test.src, globals); err != nil {
427 // Thread.Print, if provided.
435 print := func(thread *starlark.Thread, msg string) {
436 caller := thread.CallFrame(1)
439 thread := &starlark.Thread{Print: print}
440 if _, err := starlark.ExecFile(thread, "foo.star", src, nil); err != nil {
460 one := starlark.MakeInt(1)
468 {starlark.MakeInt64(math.MinInt64), "-9223372036854775808", "error"},
469 {starlark.MakeInt64(-1), "-1", "error"},
471 {starlark.MakeInt64(1), "1", "1"},
506 // functions, including propagation through built-ins such as 'min'.
508 def f(x): return 1//x
510 def h(): return min([1, 2, 0], key=g)
514 thread := new(starlark.Thread)
515 _, err := starlark.ExecFile(thread, "crash.star", src, nil)
519 crash.star:4:20: in h
530 // The topmost frame, if built-in, is not shown,
531 // but the name of the built-in function is shown
535 // or in Go (string.join) if x is non-zero.
537 def f(): ''.join([1//i])
545 1: `Traceback (most recent call last):
551 _, err := starlark.ExecFile(thread, "crash.star", src2, globals)
562 // https://github.com/google/starlark-go/pull/244
568 return 1 // x
572 thread := new(starlark.Thread)
573 thread.Load = func(t *starlark.Thread, module string) (starlark.StringDict, error) {
574 return starlark.ExecFile(new(starlark.Thread), module, loadedSrc, nil)
576 _, err := starlark.ExecFile(thread, "root.star", src, nil)
579 root.star:2:1: in <toplevel>
630 thread := new(starlark.Thread)
631 if globals, err := prog.Init(thread, predeclared); err != nil {
656 // TestUnpackUserDefined tests that user-defined
722 {starlark.MakeInt(-1), new(int32), "-1"},
723 // Use Lsh not 1<<40 as the latter exceeds int if GOARCH=386.
724 …{starlark.MakeInt(1).Lsh(40), new(int32), "1099511627776 out of range (want value in signed 32-bit…
725 …{starlark.MakeInt(-1).Lsh(40), new(int32), "-1099511627776 out of range (want value in signed 32-b…
729 …{starlark.MakeInt(0x10000), new(uint16), "65536 out of range (want value in unsigned 16-bit range)…
730 {starlark.MakeInt(-1), new(uint16), "-1 out of range (want value in unsigned 16-bit range)"},
745 globals, _ := starlark.ExecFile(&starlark.Thread{}, "doc.star", `
759 trace := func(thread *starlark.Thread) string {
761 for i := 0; i < thread.CallStackDepth(); i++ {
762 fr := thread.DebugFrame(i)
773 buf.WriteString("...") // a built-in function
781 …builtin := func(thread *starlark.Thread, _ *starlark.Builtin, _ starlark.Tuple, _ []starlark.Tuple…
782 got = trace(thread)
788 _, err := starlark.ExecFile(&starlark.Thread{}, "foo.star", `
802 `[1:]
839 // Regression test for github.com/google/starlark-go/issues/233.
841 thread := new(starlark.Thread)
848 if err := starlark.ExecREPLChunk(f, thread, globals); err != nil {
858 exec("x += 1; y = y + 1")
859 if got, want := fmt.Sprintf("%v %v", globals["x"], globals["y"]), "1 1"; got != want {
865 // A thread cancelled before it begins executes no code.
867 thread := new(starlark.Thread)
868 thread.Cancel("nope")
869 _, err := starlark.ExecFile(thread, "precancel.star", `x = 1//0`, nil)
875 _, err = starlark.ExecFile(thread, "precancel.star", `x = 1//0`, nil)
880 // A thread cancelled during a built-in executes no more code.
882 thread := new(starlark.Thread)
884 …"stopit": starlark.NewBuiltin("stopit", func(thread *starlark.Thread, b *starlark.Builtin, args st…
885 thread.Cancel(fmt.Sprint(args[0]))
889 …_, err := starlark.ExecFile(thread, "stopit.star", `msg = 'nope'; stopit(msg); x = 1//0`, predecla…
897 // A Thread records the number of computation steps.
898 thread := new(starlark.Thread)
901 steps0 := thread.ExecutionSteps()
902 …_, err := starlark.ExecFile(thread, "steps.star", `squares = [x*x for x in range(n)]`, predeclared)
903 return thread.ExecutionSteps() - steps0, err
918 thread.SetMaxExecutionSteps(1000)
928 cmd := exec.Command("go", "list", "-deps")