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

Function TestIssue154

expr_test.go:1853–1911  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1851}
1852
1853func TestIssue154(t *testing.T) {
1854 type Data struct {
1855 Array *[2]any
1856 Slice *[]any
1857 Map *map[string]any
1858 String *string
1859 }
1860
1861 type Env struct {
1862 Data *Data
1863 }
1864
1865 b := true
1866 i := 10
1867 s := "value"
1868
1869 Array := [2]any{
1870 &b,
1871 &i,
1872 }
1873
1874 Slice := []any{
1875 &b,
1876 &i,
1877 }
1878
1879 Map := map[string]any{
1880 "Bool": &b,
1881 "Int": &i,
1882 }
1883
1884 env := Env{
1885 Data: &Data{
1886 Array: &Array,
1887 Slice: &Slice,
1888 Map: &Map,
1889 String: &s,
1890 },
1891 }
1892
1893 tests := []string{
1894 `Data.Array[0] == true`,
1895 `Data.Array[1] == 10`,
1896 `Data.Slice[0] == true`,
1897 `Data.Slice[1] == 10`,
1898 `Data.Map["Bool"] == true`,
1899 `Data.Map["Int"] == 10`,
1900 `Data.String == "value"`,
1901 }
1902
1903 for _, input := range tests {
1904 program, err := expr.Compile(input, expr.Env(env))
1905 require.NoError(t, err, input)
1906
1907 output, err := expr.Run(program, env)
1908 require.NoError(t, err)
1909 assert.True(t, output.(bool), input)
1910 }

Callers

nothing calls this directly

Calls 5

CompileFunction · 0.92
EnvStruct · 0.92
NoErrorFunction · 0.92
RunFunction · 0.92
TrueFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…