Skip to content

Commit

Permalink
Add test to make sure fileReader/fileWriter queries are working in th…
Browse files Browse the repository at this point in the history
…e intermediate state

Signed-off-by: Ben Harshbarger <[email protected]>
  • Loading branch information
benharsh committed Sep 10, 2023
1 parent 27e02e0 commit 74afa0f
Show file tree
Hide file tree
Showing 2 changed files with 386 additions and 0 deletions.
106 changes: 106 additions & 0 deletions test/deprecated/IO/iokind/kind-queries.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
use IO;
use JSON;

// Part 1: make sure we can specify locking and (de)serializerType
// positionally.

proc foo(writer: fileWriter(?)) {
writeln("foo: fully generic: ", writer.type:string);
}

proc foo(writer: fileWriter(false, defaultSerializer)) {
writeln("foo: fileWriter(false): ", writer.type:string);
}

proc foo(reader: fileReader(?)) {
writeln("foo: fully generic: ", reader.type:string);
}

proc foo(reader: fileReader(false, defaultDeserializer)) {
writeln("foo: fileReader(false): ", reader.type:string);
}

// Part 2: make sure we can specify kind with a named arg

proc bar(writer: fileWriter(?)) {
writeln("bar: fileWriter(?): ", writer.type:string);
}

proc bar(writer: fileWriter(kind=_iokind.native, ?)) {
writeln("bar: fileWriter(kind=iokind.native, ?): ", writer.type:string);
}

proc bar(reader: fileReader(?)) {
writeln("bar: fileReader(?): ", reader.type:string);
}

proc bar(reader: fileReader(kind=_iokind.native, ?)) {
writeln("bar: fileReader(kind=iokind.native, ?): ", reader.type:string);
}

// Part 3: various actual queries of generic fields

proc query(writer: fileWriter(?L, ?ST)) {
writeln("L = ", L:string, " :: ST = ", ST:string);
}

proc query(reader: fileReader(?L, ?DT)) {
writeln("L = ", L:string, " :: DT = ", DT:string);
}

proc queryNamed(writer: fileWriter(locking=?L, serializerType=?ST)) {
writeln("L = ", L:string, " :: ST = ", ST:string);
}

proc queryNamed(reader: fileReader(locking=?L, deserializerType=?DT)) {
writeln("L = ", L:string, " :: DT = ", DT:string);
}

proc queryKind(writer: fileWriter(kind=?K, ?L, ?ST)) {
writeln("L = ", L:string, " :: ST = ", ST:string, " :: K = ", K:string);
}

proc queryKind(reader: fileReader(kind=?K, ?L, ?DT)) {
writeln("L = ", L:string, " :: DT = ", DT:string, " :: K = ", K:string);
}

proc queryKindLast(writer: fileWriter(?L, ?ST, kind=?K)) {
writeln("L = ", L:string, " :: ST = ", ST:string, " :: K = ", K:string);
}

proc queryKindLast(reader: fileReader(?L, ?DT, kind=?K)) {
writeln("L = ", L:string, " :: DT = ", DT:string, " :: K = ", K:string);
}

proc helper(type channel, param locking: bool, type deserType) {
type T = if channel == fileWriter(?) then deserType
else if deserType == defaultSerializer then defaultDeserializer
else if deserType == jsonSerializer then jsonDeserializer
else nothing;
var w : channel(locking, T);
writeln("----- ", w.type:string, " -----");
foo(w);
bar(w);
query(w);
queryNamed(w);
queryKind(w);
queryKindLast(w);
{
var nw : channel(_iokind.native, locking, T);
bar(nw);
queryKind(nw);
}
writeln();
}

proc helper(param locking: bool, type deserType) {
helper(fileWriter(?), locking, deserType);
helper(fileReader(?), locking, deserType);
}

proc main() {
helper(true, defaultSerializer);
helper(false, defaultSerializer);
helper(true, jsonSerializer);
helper(false, jsonSerializer);
}
Loading

0 comments on commit 74afa0f

Please sign in to comment.