diff options
Diffstat (limited to 'graphics/asymptote/tests/template')
4 files changed, 69 insertions, 0 deletions
diff --git a/graphics/asymptote/tests/template/imports/wrapper.asy b/graphics/asymptote/tests/template/imports/wrapper.asy new file mode 100644 index 0000000000..1e44cdd793 --- /dev/null +++ b/graphics/asymptote/tests/template/imports/wrapper.asy @@ -0,0 +1,12 @@ +typedef import(T); + +struct Wrapper_T { + T t; + void operator init(T t) { + this.t = t; + } +} + +Wrapper_T wrap(T t) { + return Wrapper_T(t); +}
\ No newline at end of file diff --git a/graphics/asymptote/tests/template/imports/wrapperWithEquals.asy b/graphics/asymptote/tests/template/imports/wrapperWithEquals.asy new file mode 100644 index 0000000000..0423112e65 --- /dev/null +++ b/graphics/asymptote/tests/template/imports/wrapperWithEquals.asy @@ -0,0 +1,11 @@ +typedef import(T); + +access "template/imports/wrapper"(T=T) as wrapper; +unravel wrapper; + +bool operator == (Wrapper_T a, Wrapper_T b) { + return a.t == b.t; +} +bool operator != (Wrapper_T a, Wrapper_T b) { + return a.t != b.t; +}
\ No newline at end of file diff --git a/graphics/asymptote/tests/template/mapArrayTest.asy b/graphics/asymptote/tests/template/mapArrayTest.asy new file mode 100644 index 0000000000..a110b0ed69 --- /dev/null +++ b/graphics/asymptote/tests/template/mapArrayTest.asy @@ -0,0 +1,13 @@ +import TestLib; + +StartTest("mapArray"); + +from mapArray(Src=real, Dst=string) access map; + +real[] a = {1.0, 1.5, 2.5, -3.14}; +string[] b = map(new string(real x) {return (string)x;}, + a); + +assert(all(b == new string[] {"1", "1.5", "2.5", "-3.14"})); + +EndTest();
\ No newline at end of file diff --git a/graphics/asymptote/tests/template/singletype.asy b/graphics/asymptote/tests/template/singletype.asy new file mode 100644 index 0000000000..b2c9a88e01 --- /dev/null +++ b/graphics/asymptote/tests/template/singletype.asy @@ -0,0 +1,33 @@ +import TestLib; + +StartTest("singletype"); + +struct A {} + +// TODO: Should we import operator== and alias for free? +from "template/imports/wrapperWithEquals"(T=int) access + Wrapper_T as Wrapper_int, + wrap, operator ==, alias; +// TODO: Create a way to pass operator==(A, A) to the template, either +// implicitly or explicitly. +// from "template/imports/wrapperWithEquals"(T=A) access +// Wrapper_T as Wrapper_A, wrap, operator ==, alias; // error +from "template/imports/wrapper"(T=A) + access Wrapper_T as Wrapper_A, wrap, alias; + +// Basic functionality for ints: +Wrapper_int w1 = wrap(5); +Wrapper_int w2 = Wrapper_int(5); // tests constructor +assert(w1.t == 5); +assert(w2.t == 5); +assert(w1 == w2); +assert(!alias(w1, w2)); + +// Basic functionality for A: +var a = new A; +Wrapper_A w3 = wrap(a); +Wrapper_A w4 = Wrapper_A(a); // tests constructor +assert(w3.t == w4.t); +assert(!alias(w3, w4)); + +EndTest(); |