Test.hx 1005 B

12345678910111213141516171819202122232425262728
  1. class Test {
  2. static function error(msg, code) {
  3. Sys.stderr().writeString(msg);
  4. Sys.exit(code);
  5. }
  6. static function test(file:String, pos:Int, shouldExist:Bool) {
  7. var arg = '$file@$pos';
  8. var proc = new sys.io.Process("haxe", ["--display", arg]);
  9. var stderr = proc.stderr.readAll().toString();
  10. var exit = proc.exitCode();
  11. if (exit != 0) {
  12. error(arg + ":\n" + stderr, exit);
  13. } else {
  14. var exist = stderr.indexOf("<i n=\"code\"") != -1;
  15. if (shouldExist && !exist)
  16. error(arg + ":\nNo 'code' field found in the completion output:\n\n" + stderr, 1);
  17. else if (!shouldExist && exist)
  18. error(arg + ":\nThe 'code' field should not present in the completion output:\n\n" + stderr, 1);
  19. }
  20. }
  21. static function main() {
  22. test("EmptyString.hx", 60, false);
  23. test("MultiChar.hx", 60, false);
  24. test("SingleChar.hx", 60, true);
  25. }
  26. }