XmlDisplayTestCase.hx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import haxe.display.Position.Range;
  2. import utest.Assert;
  3. import Types;
  4. using Lambda;
  5. @:autoBuild(Macro.buildTestCase())
  6. class XmlDisplayTestCase implements utest.ITest {
  7. var ctx:XmlDisplayTestContext;
  8. public function new() {}
  9. // api
  10. inline function pos(name)
  11. return ctx.pos(name);
  12. inline function fields(pos)
  13. return ctx.fields(pos);
  14. inline function toplevel(pos)
  15. return ctx.toplevel(pos);
  16. inline function type(pos)
  17. return ctx.type(pos);
  18. inline function position(pos)
  19. return ctx.position(pos);
  20. inline function usage(pos)
  21. return ctx.usage(pos);
  22. inline function range(pos1, pos2)
  23. return ctx.range(pos1, pos2);
  24. inline function signature(pos1)
  25. return ctx.signature(pos1);
  26. inline function doc(pos1)
  27. return ctx.doc(pos1);
  28. inline function metadataDoc(pos1)
  29. return ctx.metadataDoc(pos1);
  30. inline function diagnostics()
  31. return ctx.diagnostics();
  32. inline function noCompletionPoint(f)
  33. return ctx.hasErrorMessage(f, "No completion point");
  34. inline function typeNotFound(f, typeName)
  35. return ctx.hasErrorMessage(f, "Type not found : " + typeName);
  36. function assert(v:Bool)
  37. Assert.isTrue(v);
  38. function eq<T>(expected:T, actual:T, ?pos:haxe.PosInfos) {
  39. Assert.equals(expected, actual, pos);
  40. }
  41. function arrayEq<T>(expected:Array<T>, actual:Array<T>, ?pos:haxe.PosInfos) {
  42. Assert.same(expected, actual, pos);
  43. }
  44. function arrayCheck<T>(expected:Array<T>, actual:Array<T>, f:T->String, ?pos:haxe.PosInfos) {
  45. var expected = [for (expected in expected) f(expected) => expected];
  46. for (actual in actual) {
  47. var key = f(actual);
  48. Assert.isTrue(expected.exists(key), "Result not part of expected Array: " + Std.string(actual), pos);
  49. expected.remove(key);
  50. }
  51. for (expected in expected) {
  52. Assert.fail("Expected result was not part of actual Array: " + Std.string(expected), pos);
  53. return;
  54. }
  55. }
  56. function hasField(a:Array<FieldElement>, name:String, type:String, ?kind:String):Bool {
  57. return a.exists(t -> isField(t, name, type, kind));
  58. }
  59. function isField(t:FieldElement, name:String, ?type:String, ?kind:String):Bool {
  60. return (type == null || t.type == type) && t.name == name && (kind == null || t.kind == kind);
  61. }
  62. function hasToplevel(a:Array<ToplevelElement>, kind:String, name:String, ?type:String = null):Bool {
  63. return a.exists(t -> isToplevel(t, name, type, kind));
  64. }
  65. function isToplevel(t:ToplevelElement, name:String, ?type:String = null, ?kind:String = null):Bool {
  66. return (kind == null || t.kind == kind) && t.name == name && (type == null || t.type == type);
  67. }
  68. function hasPath(a:Array<FieldElement>, name:String):Bool {
  69. return a.exists(function(t) return t.name == name);
  70. }
  71. function diagnosticsRange(start:Position, end:Position):Range {
  72. var range = ctx.source.findRange(start, end);
  73. // this is probably correct...?
  74. range.start.character--;
  75. range.end.character--;
  76. return range;
  77. }
  78. function sigEq(arg:Int, params:Array<Array<String>>, sig:SignatureHelp, ?pos:haxe.PosInfos) {
  79. eq(arg, sig.activeParameter, pos);
  80. eq(params.length, sig.signatures.length, pos);
  81. for (i in 0...params.length) {
  82. var sigInf = sig.signatures[i];
  83. var args = params[i];
  84. eq(sigInf.parameters.length, args.length, pos);
  85. for (i in 0...args.length) {
  86. eq(sigInf.parameters[i].label, args[i], pos);
  87. }
  88. }
  89. }
  90. function report(message, pos:haxe.PosInfos) {
  91. Assert.fail(message, pos);
  92. }
  93. }