Permalink
Browse files

Tests for passing and returning arrays of strings.

  • Loading branch information...
1 parent 731f841 commit 6437bbb8f4fb9b2371e5d9920ecdd86c2047538d @jnthn committed Jan 13, 2012
Showing with 26 additions and 12 deletions.
  1. +1 −1 t/05-arrays.c
  2. +25 −11 t/05-arrays.t
View
@@ -31,5 +31,5 @@ DLLEXPORT char ** ReturnAStringArray()
DLLEXPORT int TakeAStringArrayAndReturnTotalLength(char **arr)
{
- return strlen(arr[0]) + strlen(arr[1]);
+ return (int)(strlen(arr[0]) + strlen(arr[1]));
}
View
@@ -2,19 +2,33 @@ use t::CompileTestLib;
use NativeCall;
use Test;
-plan 4;
+plan 7;
compile_test_lib('05-arrays');
-sub ReturnADoubleArray() returns CArray[num] is native("05-arrays") { * }
-my @rarr := ReturnADoubleArray();
-is_approx @rarr[0], 23.45e0, 'returning double array (1)';
-is_approx @rarr[1], -99.87e0, 'returning double array (1)';
-is_approx @rarr[2], 0.25e0, 'returning double array (1)';
+{
+ sub ReturnADoubleArray() returns CArray[num] is native("05-arrays") { * }
+ my @rarr := ReturnADoubleArray();
+ is_approx @rarr[0], 23.45e0, 'returning double array (1)';
+ is_approx @rarr[1], -99.87e0, 'returning double array (2)';
+ is_approx @rarr[2], 0.25e0, 'returning double array (3)';
-sub TakeADoubleArrayAndAddElements(CArray[num]) returns num is native("05-arrays") { * }
-my @parr := CArray[num].new();
-@parr[0] = 9.5e0;
-@parr[1] = 32.5e0;
-is_approx TakeADoubleArrayAndAddElements(@parr), 42e0, 'passing double array';
+ sub TakeADoubleArrayAndAddElements(CArray[num]) returns num is native("05-arrays") { * }
+ my @parr := CArray[num].new();
+ @parr[0] = 9.5e0;
+ @parr[1] = 32.5e0;
+ is_approx TakeADoubleArrayAndAddElements(@parr), 42e0, 'passing double array';
+}
+{
+ sub ReturnAStringArray() returns CArray[Str] is native("05-arrays") { * }
+ my @rarr := ReturnAStringArray();
+ is @rarr[0], 'La Trappe', 'returning string array (1)';
+ is @rarr[1], 'Leffe', 'returning string array (2)';
+
+ sub TakeAStringArrayAndReturnTotalLength(CArray[Str]) returns int32 is native("05-arrays") { * }
+ my @parr := CArray[Str].new();
+ @parr[0] = "OMG";
+ @parr[1] = "strings!!!";
+ is TakeAStringArrayAndReturnTotalLength(@parr), 13, 'passing string array';
+}

0 comments on commit 6437bbb

Please sign in to comment.