public void Importing_less_file_not_found_throws_useful_exception() { var root = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString())); try { var bundleA = root.CreateSubdirectory("bundle-a"); file.SetupGet(f => f.Directory) .Returns(new FileSystemDirectory(bundleA.FullName)); root.CreateSubdirectory("bundle-b"); var compiler = new LessCompiler(); var exception = Assert.Throws <LessCompileException>(delegate { compiler.Compile( "@import \"../bundle-b/_MISSING.less\";\nbody{ color: @color }", file.Object ); }); exception.Message.ShouldContain("_MISSING.less"); exception.Message.ShouldContain("test.less"); } finally { root.Delete(true); } }
public void Can_Compile_LESS_with_two_levels_of_import() { // Mocking out IFileSystem here would be lots of work, given the directory navigations // that are required. So it's easier to use a temp directory and a real FileSystemDirectory object. var root = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString())); var bundleA = root.CreateSubdirectory("bundle-a"); var bundleB = root.CreateSubdirectory("bundle-b"); file.SetupGet(f => f.Directory) .Returns(new FileSystemDirectory(bundleA.FullName)); try { File.WriteAllText( Path.Combine(root.FullName, "_base.less"), "@size: 100px;" ); File.WriteAllText( Path.Combine(bundleB.FullName, "_lib.less"), "@import \"../_base.less\";\n@color: red; p { height: @size; }" ); var compiler = new LessCompiler(); var css = compiler.Compile( "@import \"../bundle-b/_lib.less\";\nbody{ color: @color }", file.Object ); css.ShouldEqual("p {\n height: 100px;\n}\nbody {\n color: red;\n}\n"); } finally { root.Delete(true); } }
public void Compile_converts_LESS_into_CSS() { var compiler = new LessCompiler(); var css = compiler.Compile("@color: #4d926f; #header { color: @color; }", file.Object); css.ShouldEqual("#header {\n color: #4d926f;\n}\n"); }
public void Compile_invalid_LESS_throws_exception() { var compiler = new LessCompiler(); var exception = Assert.Throws <LessCompileException>(delegate { compiler.Compile("#unclosed_rule {", file.Object); }); exception.Message.ShouldStartWith("Missing closing '}' on line 1 in file 'test.less':"); }
public void Compile_LESS_that_fails_parsing_throws_LessCompileException() { var compiler = new LessCompiler(); var exception = Assert.Throws <LessCompileException>(delegate { compiler.Compile("#fail { - }", file.Object); }); exception.Message.ShouldStartWith("Expected '}' on line 1 in file 'test.less':"); }
public void Compile_LESS_with_unknown_mixin_throws_exception() { var less = "form { \nmargin-bottom: @baseline; }"; var compiler = new LessCompiler(); var exception = Assert.Throws <LessCompileException>(delegate { compiler.Compile(less, file.Object); }); exception.Message.ShouldStartWith("variable @baseline is undefined on line 2 in file 'test.less':"); }
public void Import_less_file_that_uses_outer_variable() { StubFile("Framework.less", ".object { padding: @objectpadding; }"); var compiler = new LessCompiler(); var result = compiler.Compile( "@objectpadding: 20px;\n@import \"Framework.less\";", file.Object ); result.ShouldEqual(".object {\n padding: 20px;\n}\n"); }
public void Can_Compile_LESS_that_imports_another_LESS_file() { StubFile("lib.less", "@color: white;"); var compiler = new LessCompiler(); var css = compiler.Compile( "@import \"lib\";\nbody{ color: @color }", file.Object ); css.ShouldEqual("body {\n color: white;\n}\n"); }
public void Can_Compile_LESS_that_imports_another_LESS_file_from_different_directory() { StubFile("../bundle-b/lib.less", "@color: red;"); var compiler = new LessCompiler(); var css = compiler.Compile( "@import \"../bundle-b/lib.less\";\nbody{ color: @color }", file.Object ); css.ShouldEqual("body {\n color: red;\n}\n"); }
public CompilingMainTwitterBootstrapLessFile() { var source = File.ReadAllText("bootstrap\\bootstrap.less"); var context = new CompileContext { RootDirectory = new FileSystemDirectory(Path.GetFullPath(".")), SourceFilePath = "bootstrap/bootstrap.less" }; var lessCompiler = new LessCompiler(); var result = lessCompiler.Compile(source, context); importedFilePaths = result.ImportedFilePaths; }
public void Using_mixin_from_imported_css_file_throws_exception() { StubFile("lib.css", ".mixin { color: red; }"); var compiler = new LessCompiler(); Assert.Throws <LessCompileException>(delegate { compiler.Compile( "@import \"lib.css\";\nbody{ .mixin; }", file.Object ); }); }
public void Can_Compile_LESS_that_imports_another_LESS_file() { var otherFile = new Mock<IFile>(); directory.Setup(d => d.GetFile("lib.less")) .Returns(otherFile.Object); otherFile.Setup(f => f.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) .Returns(() => "@color: #ffffff;".AsStream()); var compiler = new LessCompiler(); var css = compiler.Compile( "@import \"lib\";\nbody{ color: @color }", file.Object ); css.ShouldEqual("body {\n color: #ffffff;\n}\n"); }
public void Variable_defined_by_nested_import_is_replaced_in_CSS_output() { using (var path = new TempDirectory()) { File.WriteAllText(Path.Combine(path, "main.less"), "@import 'first.less';\np { color: @c }"); File.WriteAllText(Path.Combine(path, "first.less"), "@import 'second.less';"); File.WriteAllText(Path.Combine(path, "second.less"), "@c: red;"); var directory = new FileSystemDirectory(path); var file = directory.GetFile("main.less"); var compiler = new LessCompiler(); var css = compiler.Compile(file.OpenRead().ReadToEnd(), file); css.ShouldContain("color: red;"); } }
public void Using_mixin_from_imported_css_file_throws_exception() { var otherFile = new Mock<IFile>(); directory.Setup(d => d.GetFile("lib.css")) .Returns(otherFile.Object); otherFile.Setup(f => f.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) .Returns(() => ".mixin { color: red; }".AsStream()); var compiler = new LessCompiler(); Assert.Throws<LessCompileException>(delegate { compiler.Compile( "@import \"lib.css\";\nbody{ .mixin; }", file.Object ); }); }
public void Import_less_file_that_uses_outer_variable() { var otherFile = new Mock<IFile>(); directory.Setup(d => d.GetFile("Framework.less")) .Returns(otherFile.Object); otherFile.Setup(f => f.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) .Returns(() => ".object { padding: @objectpadding; }".AsStream()); var compiler = new LessCompiler(); var result = compiler.Compile( "@objectpadding: 20px;\n@import \"Framework.less\";", file.Object ); result.ShouldEqual(".object {\n padding: 20px;\n}\n"); }
public void Importing_less_file_not_found_throws_useful_exception() { var root = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString())); try { var bundleA = root.CreateSubdirectory("bundle-a"); file.SetupGet(f => f.Directory) .Returns(new FileSystemDirectory(bundleA.FullName)); root.CreateSubdirectory("bundle-b"); var compiler = new LessCompiler(); var exception = Assert.Throws<FileNotFoundException>(delegate { compiler.Compile( "@import \"../bundle-b/_MISSING.less\";\nbody{ color: @color }", file.Object ); }); exception.Message.ShouldContain("_MISSING.less"); exception.Message.ShouldContain("test.less"); } finally { root.Delete(true); } }
public void Compile_LESS_with_unknown_mixin_throws_exception() { var less = "form { \nmargin-bottom: @baseline; }"; var compiler = new LessCompiler(); var exception = Assert.Throws<LessCompileException>(delegate { compiler.Compile(less, file.Object); }); exception.Message.ShouldEqual("Less compile error in test.less:\r\nvariable @baseline is undefined"); }
public void Compile_LESS_that_fails_parsing_throws_LessCompileException() { var compiler = new LessCompiler(); var exception = Assert.Throws<LessCompileException>(delegate { compiler.Compile("#fail { - }", file.Object); }); exception.Message.ShouldEqual("Less compile error in test.less:\r\nSyntax Error on line 1"); }
public void Compile_invalid_LESS_throws_exception() { var compiler = new LessCompiler(); var exception = Assert.Throws<LessCompileException>(delegate { compiler.Compile("#unclosed_rule {", file.Object); }); exception.Message.ShouldEqual("Less compile error in test.less:\r\nMissing closing `}`"); }
public void Compile_converts_LESS_into_CSS() { var compiler = new LessCompiler(); var css = compiler.Compile("@color: #4d926f; #header { color: @color; }", file.Object); css.ShouldEqual("#header {\n color: #4d926f;\n}\n"); }
public void Can_Compile_LESS_with_two_levels_of_import() { // Mocking out IFileSystem here would be lots of work, given the directory navigations // that are required. So it's easier to use a temp directory and a real FileSystemDirectory object. var root = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString())); var bundleA = root.CreateSubdirectory("bundle-a"); var bundleB = root.CreateSubdirectory("bundle-b"); file.SetupGet(f => f.Directory) .Returns(new FileSystemDirectory(bundleA.FullName)); try { File.WriteAllText( Path.Combine(root.FullName, "_base.less"), "@size: 100px;" ); File.WriteAllText( Path.Combine(bundleB.FullName, "_lib.less"), "@import \"../_base.less\";\n@color: #ffffff; p { height: @size; }" ); var compiler = new LessCompiler(); var css = compiler.Compile( "@import \"../bundle-b/_lib.less\";\nbody{ color: @color }", file.Object ); css.ShouldEqual("p {\n height: 100px;\n}\nbody {\n color: #ffffff;\n}\n"); } finally { root.Delete(true); } }
public void Compile_converts_LESS_into_CSS() { var css = compiler.Compile("@color: #4d926f; #header { color: @color; }", compileContext); css.Output.ShouldEqual("#header {\n color: #4d926f;\n}\n"); }