1
0

index.html 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <title>CodeMirror: VB.NET mode</title>
  5. <link rel="stylesheet" href="../../lib/codemirror.css">
  6. <script src="../../lib/codemirror.js"></script>
  7. <script src="vb.js"></script>
  8. <link rel="stylesheet" href="../../doc/docs.css">
  9. <link href="http://fonts.googleapis.com/css?family=Inconsolata" rel="stylesheet" type="text/css">
  10. <style>
  11. .CodeMirror {border: 1px solid #aaa; height:210px; height: auto;}
  12. .CodeMirror-scroll { overflow-x: auto; overflow-y: hidden;}
  13. .CodeMirror pre { font-family: Inconsolata; font-size: 14px}
  14. </style>
  15. <script type="text/javascript" src="../../addon/runmode/runmode.js"></script>
  16. </head>
  17. <body onload="init()">
  18. <h1>CodeMirror: VB.NET mode</h1>
  19. <script type="text/javascript">
  20. function test(golden, text) {
  21. var ok = true;
  22. var i = 0;
  23. function callback(token, style, lineNo, pos){
  24. //console.log(String(token) + " " + String(style) + " " + String(lineNo) + " " + String(pos));
  25. var result = [String(token), String(style)];
  26. if (golden[i][0] != result[0] || golden[i][1] != result[1]){
  27. return "Error, expected: " + String(golden[i]) + ", got: " + String(result);
  28. ok = false;
  29. }
  30. i++;
  31. }
  32. CodeMirror.runMode(text, "text/x-vb",callback);
  33. if (ok) return "Tests OK";
  34. }
  35. function testTypes() {
  36. var golden = [['Integer','keyword'],[' ','null'],['Float','keyword']]
  37. var text = "Integer Float";
  38. return test(golden,text);
  39. }
  40. function testIf(){
  41. var golden = [['If','keyword'],[' ','null'],['True','keyword'],[' ','null'],['End','keyword'],[' ','null'],['If','keyword']];
  42. var text = 'If True End If';
  43. return test(golden, text);
  44. }
  45. function testDecl(){
  46. var golden = [['Dim','keyword'],[' ','null'],['x','variable'],[' ','null'],['as','keyword'],[' ','null'],['Integer','keyword']];
  47. var text = 'Dim x as Integer';
  48. return test(golden, text);
  49. }
  50. function testAll(){
  51. var result = "";
  52. result += testTypes() + "\n";
  53. result += testIf() + "\n";
  54. result += testDecl() + "\n";
  55. return result;
  56. }
  57. function initText(editor) {
  58. var content = 'Class rocket\nPrivate quality as Double\nPublic Sub launch() as String\nif quality > 0.8\nlaunch = "Successful"\nElse\nlaunch = "Failed"\nEnd If\nEnd sub\nEnd class\n';
  59. editor.setValue(content);
  60. for (var i =0; i< editor.lineCount(); i++) editor.indentLine(i);
  61. }
  62. function init() {
  63. editor = CodeMirror.fromTextArea(document.getElementById("solution"), {
  64. lineNumbers: true,
  65. mode: "text/x-vb",
  66. readOnly: false,
  67. tabMode: "shift"
  68. });
  69. runTest();
  70. }
  71. function runTest() {
  72. document.getElementById('testresult').innerHTML = testAll();
  73. initText(editor);
  74. }
  75. </script>
  76. <div id="edit">
  77. <textarea style="width:95%;height:200px;padding:5px;" name="solution" id="solution" ></textarea>
  78. </div>
  79. <pre id="testresult"></pre>
  80. <p>MIME type defined: <code>text/x-vb</code>.</p>
  81. </body></html>