Skip to content

Commit

Permalink
Merge pull request #485 from agemogolk/tests
Browse files Browse the repository at this point in the history
Update test suite.
  • Loading branch information
agemogolk committed Jan 24, 2013
2 parents 533f840 + 6736821 commit 3f964a3
Show file tree
Hide file tree
Showing 28 changed files with 784 additions and 767 deletions.
7 changes: 3 additions & 4 deletions lib-clay/core/operators/operators.clay
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ forceinline default assign(ref dest:T, rvalue src:T) : {

[T when
not BitwiseAssignedType?(T)
and CallDefined?(copy, T)
and CallDefined?(move, T)
and Copyable?(T)
and Movable?(T)
and not CopyDoesNotThrowType?(T)]
forceinline overload assign(ref dest:T, ref src:T) : {
var tmp = moveUnsafe(dest);
Expand All @@ -110,8 +110,7 @@ forceinline overload assign(ref dest:T, ref src:T) : {

[T when
not BitwiseAssignedType?(T)
and CallDefined?(copy, T)
and CallDefined?(move, T)
and Copyable?(T)
and CopyDoesNotThrowType?(T)]
forceinline overload assign(ref dest:T, ref src:T) : {
destroy(dest);
Expand Down
4 changes: 2 additions & 2 deletions lib-clay/test/test.clay
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ alias expectCallDefined(Proc, ..Types) {
TEST_FAIL_CASE_INDENT, ..weaveValues(", ", ..Types)));
}

alias expectCallUndefined(Proc, ..Types) {
expectCallUndefined(Proc, ..Types) {
expect(
not CallDefined?(Proc, ..Types),
str("`", Proc, "` shouldn't be callable with the expected argument types:\n",
Expand Down Expand Up @@ -315,7 +315,7 @@ required(block) {
throw RequiredExpectationFailed();
}

var testOptionSpecs = OptionSpecs(
var testOptionSpecs = vector(
OptionSpec("s", "suite", HAS_VALUE, ALLOWS_REPEATS),
OptionSpec("c", "case", HAS_VALUE, ALLOWS_REPEATS),
OptionSpec("n", "nc", "no-color")
Expand Down
5 changes: 1 addition & 4 deletions test/lang/codepointers/30/main.clay
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,7 @@ overload display(x:Displayable) {
}

main() {
var v = Vector[Displayable]();
push(v, Displayable(1));
push(v, Displayable(3.2));
push(v, Displayable("Hi!"));
var v = vector(Displayable(1), Displayable(3.2), Displayable("Hi!"));
for (x in v)
display(x);
}
55 changes: 28 additions & 27 deletions test/lang/operators/pod/test.clay
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import
test.*,
test.module.*,
uniquepointers.(UniquePointer),
sharedpointers.*,
simd.*,
Expand All @@ -17,30 +18,30 @@ variant NonPODVariant (Int, NonPODRecord);

enum Enum ( A, B, C );

main() = testMain(TestSuite("PODType?", array(
TestCase("PODType?", -> {
expectFalse(PODType?(IrregularRecord));
expectTrue (PODType?(PODRecord));
expectFalse(PODType?(NonPODRecord));
expectTrue (PODType?(Array[Int, 2]));
expectFalse(PODType?(Array[IrregularRecord, 2]));
expectTrue (PODType?(Vec[Int, 2]));
expectTrue (PODType?(Tuple[]));
expectTrue (PODType?(Tuple[Int, Float]));
expectFalse(PODType?(Tuple[Int, IrregularRecord]));
expectTrue (PODType?(Union[]));
expectTrue (PODType?(Union[Int, Float]));

expectTrue (PODType?(Char));
expectTrue (PODType?(StringLiteralRef));
expectFalse(PODType?(SharedPointer[Int]));
expectFalse(PODType?(UniquePointer[Int]));
expectFalse(PODType?(Vector[Int]));
expectFalse(PODType?(String));

expectTrue (PODType?(PODVariant));
expectFalse(PODType?(NonPODVariant));

expectTrue (PODType?(Enum));
}),
)));
TEST_PODType?() {
expectFalse(PODType?(IrregularRecord));
expectTrue (PODType?(PODRecord));
expectFalse(PODType?(NonPODRecord));
expectTrue (PODType?(Array[Int, 2]));
expectFalse(PODType?(Array[IrregularRecord, 2]));
expectTrue (PODType?(Vec[Int, 2]));
expectTrue (PODType?(Tuple[]));
expectTrue (PODType?(Tuple[Int, Float]));
expectFalse(PODType?(Tuple[Int, IrregularRecord]));
expectTrue (PODType?(Union[]));
expectTrue (PODType?(Union[Int, Float]));

expectTrue (PODType?(Char));
expectTrue (PODType?(StringLiteralRef));
expectFalse(PODType?(SharedPointer[Int]));
expectFalse(PODType?(UniquePointer[Int]));
expectFalse(PODType?(Vector[Int]));
expectFalse(PODType?(String));

expectTrue (PODType?(PODVariant));
expectFalse(PODType?(NonPODVariant));

expectTrue (PODType?(Enum));
}

private main() = testMainModule();
2 changes: 1 addition & 1 deletion test/lib-clay/algorithms/permutations/test.clay
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ baseTestCase(n) =

main() = testMain(
TestSuite("Permutations of integer ranges", map(baseTestCase, range(1, 7)))
);
);
101 changes: 52 additions & 49 deletions test/lib-clay/algorithms/sorting/test.clay
Original file line number Diff line number Diff line change
@@ -1,56 +1,59 @@
import test.*;
import data.algorithms.(sort,sortBy);
import comparators.(comparing,reversed);
import printer.(str);
import data.vectors.*;
import
test.*,
test.module.*,
data.algorithms.(sort,sortBy),
comparators.(comparing,reversed),
printer.(str),
data.vectors.*;

record Unordered[T](value : T);

main() = testMain(
TestSuite("sorting", array(
TestCase("In ascending order", -> {
var baseSequence = array(10, 9, 8, 1, 2, 7, 6, 2, 3, 4);
var sortedSequence = array(1, 2, 2, 3, 4, 6, 7, 8, 9, 10);

sort(baseSequence);
expectEqual(sortedSequence, baseSequence);
}),
TestCase("In descending order", -> {
var baseSequence = array(10, 9, 8, 1, 2, 7, 6, 2, 3, 4);
var sortedSequence = array(10, 9, 8, 7, 6, 4, 3, 2, 2, 1);

sortBy(baseSequence, reversed());
expectEqual(sortedSequence, baseSequence);
}),
TestCase("Comparing size", -> {
var baseSequence = array("a", "b", "c", "blargh", "foo", "de", "x", "stuff");
sortBy(baseSequence, comparing(size));

var isFirst = true;
var last = StringLiteralRef("ignore me");

for(x in baseSequence){
if(isFirst){
last = x;
isFirst = false;
} else {
expectTrue(size(last) <= size(x));
last = x;
}
TEST_ascending_order() {
var baseSequence = array(10, 9, 8, 1, 2, 7, 6, 2, 3, 4);
var sortedSequence = array(1, 2, 2, 3, 4, 6, 7, 8, 9, 10);

sort(baseSequence);
expectEqual(sortedSequence, baseSequence);
}

TEST_descending_order() {
var baseSequence = array(10, 9, 8, 1, 2, 7, 6, 2, 3, 4);
var sortedSequence = array(10, 9, 8, 7, 6, 4, 3, 2, 2, 1);

sortBy(baseSequence, reversed());
expectEqual(sortedSequence, baseSequence);
}

TEST_comparing_size() {
var baseSequence = array("a", "b", "c", "blargh", "foo", "de", "x", "stuff");
sortBy(baseSequence, comparing(size));

var isFirst = true;
var last = StringLiteralRef("ignore me");

for(x in baseSequence){
if(isFirst){
last = x;
isFirst = false;
} else {
expectTrue(size(last) <= size(x));
last = x;
}
}),
TestCase("for something not naturally orderable", -> {
var sequence = Vector[Unordered[Int]]();
}
}

for(i in range(10)){
push(sequence, Unordered(i));
}
TEST_for_something_not_naturally_orderable() {
var sequence = Vector[Unordered[Int]]();

sortBy(sequence, reversed(comparing(x => x.value)));
for(i in range(10)){
push(sequence, Unordered(i));
}

for(i in range(10)){
expectEqual(9 - i, sequence[i].value);
}
})
))
);
sortBy(sequence, reversed(comparing(x => x.value)));

for(i in range(10)){
expectEqual(9 - i, sequence[i].value);
}
}

private main() = testMainModule();
34 changes: 16 additions & 18 deletions test/lib-clay/algorithms/strings/test.clay
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import test.*;
import data.algorithms.strings.(trim);
import
test.*,
test.module.*,
data.algorithms.strings.(trim);

main() = testMain(
TestSuite(
"algorithms.strings", array(
TestCase("trim", -> {
expectEqual(
trim(" \t A string,\nthat\tneeds trimming. \n \n "),
"A string,\nthat\tneeds trimming.",
);
expectEqual(
trim("*** message ***", x => (x == '*' or x == ' ')),
"message"
);
}),
)
)
);
TEST_trim() {
expectEqual(
trim(" \t A string,\nthat\tneeds trimming. \n \n "),
"A string,\nthat\tneeds trimming.",
);
expectEqual(
trim("*** message ***", x => (x == '*' or x == ' ')),
"message"
);
}

private main() = testMainModule();
33 changes: 17 additions & 16 deletions test/lib-clay/byteorder/test.clay
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import byteorder.*;
import printer.(str);
import test.*;
import
byteorder.*,
printer.(str),
test.*,
test.module.*;

define testNetworkToHost;

Expand All @@ -19,16 +21,15 @@ overload testNetworkToHost(#IntType, function, expectReversed?) {
overload testNetworkToHost(#IntType, function, expectReversed?) {
}

main() = testMain(
TestSuite("byteorder", array(
TestCase("networkToHost, hostToNetwork", -> {
..for (IntType in UInt8, Int8, UInt16, Int16, UInt32, Int32, UInt64, Int64, UInt128, Int128) {
testNetworkToHost(IntType, networkToHost, LittleEndian?);
testNetworkToHost(IntType, hostToNetwork, LittleEndian?);
testNetworkToHost(IntType, bigToHost, LittleEndian?);
testNetworkToHost(IntType, hostToBig, LittleEndian?);
testNetworkToHost(IntType, littleToHost, BigEndian?);
testNetworkToHost(IntType, hostToLittle, BigEndian?);
}
}),
)));
TEST_networkToHost_hostToNetwork() {
..for (IntType in ..BuiltinIntegerTypes()) {
testNetworkToHost(IntType, networkToHost, LittleEndian?);
testNetworkToHost(IntType, hostToNetwork, LittleEndian?);
testNetworkToHost(IntType, bigToHost, LittleEndian?);
testNetworkToHost(IntType, hostToBig, LittleEndian?);
testNetworkToHost(IntType, littleToHost, BigEndian?);
testNetworkToHost(IntType, hostToLittle, BigEndian?);
}
}

private main() = testMainModule();
4 changes: 2 additions & 2 deletions test/lib-clay/cocoa/objc/internals/test.macosx.clay
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ expectSelectorNotCallableWith(Class, selector, ..T) {
);
}

main() = testMain(TestSuite("Objective-C binding internals", array(
main() = testMain(TestSuite("Objective-C binding internals",
TestCase("type encodings", -> {
expectEncoding("");
expectEncoding("c", Int8);
Expand Down Expand Up @@ -623,5 +623,5 @@ main() = testMain(TestSuite("Objective-C binding internals", array(

pool.drain();
}),
)));
));

4 changes: 2 additions & 2 deletions test/lib-clay/cocoa/util/test.macosx.clay
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ overload selector("initWithFoo:bar:") = Id, Id, Id;
record RegularTest = regularClass(["foo", String], ["bar", Char]);
record RegularCanary = regularClass(["foo", Canary], ["bar", Canary]);

main() = withAutoreleasePool(() => testMain(TestSuite("cocoa.util", array(
main() = withAutoreleasePool(() => testMain(TestSuite("cocoa.util",
TestCase("constructor overloads", -> {
expectEqual(true, NSNumber(true).boolValue());
expectEqual(5, NSNumber(5).intValue());
Expand Down Expand Up @@ -353,4 +353,4 @@ main() = withAutoreleasePool(() => testMain(TestSuite("cocoa.util", array(
NSUInteger(10), NSUInteger(11), NSUInteger(12), NSUInteger(13), NSUInteger(14)
);
}),
))));
)));
8 changes: 4 additions & 4 deletions test/lib-clay/commandline/options/test.clay
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import commandline.options.parser.*;
import data.strings.*;
import data.vectors.*;

fbbSpec() = OptionSpecs(array(
fbbSpec() = vector(
OptionSpec('f', "foo"),
OptionSpec('b', "bar"),
OptionSpec('z', "baz"),
OptionSpec('i', "bif")
));
);

valuableSpec() = OptionSpecs(array(
valuableSpec() = vector(
OptionSpec('f', "foo", HAS_VALUE),
OptionSpec('b', "bar", HAS_VALUE)
));
);

[T] numberOf(it, #T){
var i = 0;
Expand Down
Loading

0 comments on commit 3f964a3

Please sign in to comment.