MCPcopy
hub / github.com/expr-lang/expr / TestVM_OpcodeOperations

Function TestVM_OpcodeOperations

vm/vm_test.go:305–436  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

303}
304
305func TestVM_OpcodeOperations(t *testing.T) {
306 tests := []struct {
307 name string
308 expr string
309 env map[string]any
310 want any
311 expectError string
312 }{
313 // Arithmetic Operations
314 {
315 name: "basic addition",
316 expr: "2 + 3",
317 want: 5,
318 },
319 {
320 name: "mixed type arithmetic",
321 expr: "2.5 + 3",
322 want: 5.5,
323 },
324 {
325 name: "chained arithmetic",
326 expr: "1 + 2 * 3 - 4 / 2",
327 want: 5.0,
328 },
329 {
330 name: "modulo operation",
331 expr: "5 % 2",
332 want: 1,
333 },
334 {
335 name: "exponent operation",
336 expr: "2 ^ 3",
337 want: 8.0,
338 },
339 {
340 name: "negation",
341 expr: "-5",
342 want: -5,
343 },
344
345 // String Operations
346 {
347 name: "string concatenation",
348 expr: `"hello" + " " + "world"`,
349 want: "hello world",
350 },
351 {
352 name: "string starts with",
353 expr: `"hello world" startsWith "hello"`,
354 want: true,
355 },
356 {
357 name: "string ends with",
358 expr: `"hello world" endsWith "world"`,
359 want: true,
360 },
361 {
362 name: "string contains",

Callers

nothing calls this directly

Calls 8

RunMethod · 0.95
CompileFunction · 0.92
EnvStruct · 0.92
NoErrorFunction · 0.92
ErrorFunction · 0.92
ContainsFunction · 0.92
EqualFunction · 0.92
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…