NEW: TestCallConstructorAPI tests the CallConstructor API directly
(t *testing.T)
| 1865 | |
| 1866 | // NEW: TestCallConstructorAPI tests the CallConstructor API directly |
| 1867 | func TestCallConstructorAPI(t *testing.T) { |
| 1868 | rt := NewRuntime() |
| 1869 | defer rt.Close() |
| 1870 | ctx := rt.NewContext() |
| 1871 | defer ctx.Close() |
| 1872 | |
| 1873 | // Create Point class |
| 1874 | pointConstructor, _ := createPointClass(ctx) |
| 1875 | defer pointConstructor.Free() |
| 1876 | if pointConstructor.IsException() { |
| 1877 | err := ctx.Exception() |
| 1878 | t.Fatalf("Failed to create Point class: %v", err) |
| 1879 | } |
| 1880 | |
| 1881 | // Test CallConstructor with no arguments |
| 1882 | instance1 := pointConstructor.CallConstructor() |
| 1883 | defer instance1.Free() |
| 1884 | |
| 1885 | if instance1.IsException() { |
| 1886 | err := ctx.Exception() |
| 1887 | t.Fatalf("CallConstructor with no args failed: %v", err) |
| 1888 | } |
| 1889 | |
| 1890 | // Verify instance properties |
| 1891 | if !instance1.Has("x") || !instance1.Has("y") { |
| 1892 | t.Errorf("Instance missing accessor properties") |
| 1893 | } |
| 1894 | |
| 1895 | if !instance1.Has("version") || !instance1.Has("readOnlyFlag") { |
| 1896 | t.Errorf("Instance missing data properties") |
| 1897 | } |
| 1898 | |
| 1899 | // Test CallConstructor with arguments |
| 1900 | arg1 := ctx.NewFloat64(10.5) // Updated: Use NewFloat64() |
| 1901 | arg2 := ctx.NewFloat64(20.5) // Updated: Use NewFloat64() |
| 1902 | defer arg1.Free() |
| 1903 | defer arg2.Free() |
| 1904 | |
| 1905 | instance2 := pointConstructor.CallConstructor(arg1, arg2) |
| 1906 | defer instance2.Free() |
| 1907 | |
| 1908 | if instance2.IsException() { |
| 1909 | err := ctx.Exception() |
| 1910 | t.Fatalf("CallConstructor with args failed: %v", err) |
| 1911 | } |
| 1912 | |
| 1913 | // Verify constructor arguments were applied |
| 1914 | x := instance2.Get("x") |
| 1915 | y := instance2.Get("y") |
| 1916 | defer x.Free() |
| 1917 | defer y.Free() |
| 1918 | |
| 1919 | if math.Abs(x.ToFloat64()-10.5) > 0.001 { // Updated: Use ToFloat64() |
| 1920 | t.Errorf("Expected x=10.5, got %f", x.ToFloat64()) |
| 1921 | } |
| 1922 | if math.Abs(y.ToFloat64()-20.5) > 0.001 { // Updated: Use ToFloat64() |
| 1923 | t.Errorf("Expected y=20.5, got %f", y.ToFloat64()) |
| 1924 | } |
nothing calls this directly
no test coverage detected