NEW: TestSchemeCSynchronization tests that property changes sync with Go object
(t *testing.T)
| 1939 | |
| 1940 | // NEW: TestSchemeCSynchronization tests that property changes sync with Go object |
| 1941 | func TestSchemeCSynchronization(t *testing.T) { |
| 1942 | rt := NewRuntime() |
| 1943 | defer rt.Close() |
| 1944 | ctx := rt.NewContext() |
| 1945 | defer ctx.Close() |
| 1946 | |
| 1947 | // Create Point class |
| 1948 | pointConstructor, _ := createPointClass(ctx) |
| 1949 | if pointConstructor.IsException() { |
| 1950 | err := ctx.Exception() |
| 1951 | t.Fatalf("Failed to create Point class: %v", err) |
| 1952 | } |
| 1953 | |
| 1954 | ctx.Globals().Set("Point", pointConstructor) |
| 1955 | |
| 1956 | // Test that accessor changes sync with Go object |
| 1957 | result := ctx.Eval(` |
| 1958 | let p = new Point(1, 2); |
| 1959 | |
| 1960 | // Change values via accessors |
| 1961 | p.x = 100; |
| 1962 | p.y = 200; |
| 1963 | |
| 1964 | // Read back via accessors |
| 1965 | [p.x, p.y]; |
| 1966 | `) |
| 1967 | defer result.Free() |
| 1968 | if result.IsException() { |
| 1969 | err := ctx.Exception() |
| 1970 | t.Fatalf("Failed to evaluate synchronization test: %v", err) |
| 1971 | } |
| 1972 | |
| 1973 | if result.GetIdx(0).ToFloat64() != 100.0 || result.GetIdx(1).ToFloat64() != 200.0 { // Updated: Use ToFloat64() |
| 1974 | t.Errorf("Accessor synchronization failed: expected [100, 200], got [%f, %f]", |
| 1975 | result.GetIdx(0).ToFloat64(), result.GetIdx(1).ToFloat64()) |
| 1976 | } |
| 1977 | |
| 1978 | // Test that we can retrieve the Go object and verify synchronization |
| 1979 | instance := ctx.Eval(`p`) |
| 1980 | defer instance.Free() |
| 1981 | if instance.IsException() { |
| 1982 | err := ctx.Exception() |
| 1983 | t.Fatalf("Failed to get instance: %v", err) |
| 1984 | } |
| 1985 | |
| 1986 | goObj, err := instance.GetGoObject() |
| 1987 | if err != nil { |
| 1988 | t.Fatalf("Failed to get Go object: %v", err) |
| 1989 | } |
| 1990 | |
| 1991 | point, ok := goObj.(*Point) |
| 1992 | if !ok { |
| 1993 | t.Fatalf("Expected *Point, got %T", goObj) |
| 1994 | } |
| 1995 | |
| 1996 | if point.X != 100.0 || point.Y != 200.0 { |
| 1997 | t.Errorf("Go object synchronization failed: expected Point(100, 200), got Point(%f, %f)", |
| 1998 | point.X, point.Y) |
nothing calls this directly
no test coverage detected