1 module workspaced.com.snippets._package_tests; 2 3 import std.conv; 4 5 import workspaced.api; 6 import workspaced.com.dfmt; 7 import workspaced.com.snippets; 8 import workspaced.helpers; 9 10 unittest 11 { 12 scope backend = new WorkspaceD(); 13 auto workspace = makeTemporaryTestingWorkspace; 14 auto instance = backend.addInstance(workspace.directory); 15 backend.register!SnippetsComponent; 16 backend.register!DfmtComponent; 17 SnippetsComponent snippets = backend.get!SnippetsComponent(workspace.directory); 18 19 auto args = ["--indent_style", "tab"]; 20 21 auto res = snippets.formatSync("void main(${1:string[] args}) {\n\t$0\n}", args); 22 assert(res == "void main(${1:string[] args})\n{\n\t$0\n}"); 23 24 res = snippets.formatSync("class ${1:MyClass} {\n\t$0\n}", args); 25 assert(res == "class ${1:MyClass}\n{\n\t$0\n}"); 26 27 res = snippets.formatSync("enum ${1:MyEnum} = $2;\n$0", args); 28 assert(res == "enum ${1:MyEnum} = $2;\n$0"); 29 30 res = snippets.formatSync("import ${1:std};\n$0", args); 31 assert(res == "import ${1:std};\n$0"); 32 33 res = snippets.formatSync("import ${1:std};\n$0", args, SnippetLevel.method); 34 assert(res == "import ${1:std};\n$0"); 35 36 res = snippets.formatSync("foo(delegate() {\n${1:// foo}\n});", args, SnippetLevel.method); 37 assert(res == "foo(delegate() {\n\t${1:// foo}\n});"); 38 39 res = snippets.formatSync(`auto ${1:window} = new SimpleWindow(Size(${2:800, 600}), "$3");`, args, SnippetLevel.method); 40 assert(res == `auto ${1:window} = new SimpleWindow(Size(${2:800, 600}), "$3");`); 41 } 42 43 unittest 44 { 45 import workspaced.helpers; 46 47 scope backend = new WorkspaceD(); 48 auto workspace = makeTemporaryTestingWorkspace; 49 auto instance = backend.addInstance(workspace.directory); 50 backend.register!SnippetsComponent; 51 SnippetsComponent snippets = backend.get!SnippetsComponent(workspace.directory); 52 53 runTestDataFileTests("test/data/snippet_info", null, null, 54 (code, parts, line) { 55 assert(parts.length == 2, "malformed snippet info test line: " ~ line); 56 57 auto i = snippets.determineSnippetInfo(null, code, parts[0].to!int); 58 assert(i.level == parts[1].to!SnippetLevel, i.stack.to!string); 59 }, null); 60 }