public void PrepareTest() { var parentDirectory = Directory.GetParent(new Uri(GetType().Assembly.Location).LocalPath).FullName; var fileName = Path.Combine(parentDirectory, "Resources", "test.xml"); _objectUnderTest = Parser.Parse(fileName); _root = _objectUnderTest.Children.Single(); }
public void PrepareTest() { var parentDirectory = Directory.GetParent(new Uri(GetType().Assembly.Location).LocalPath).FullName; var fileName = Path.Combine(parentDirectory, "Resources", "Xaml_ResourceDictionary.xml"); // we need to adjust line breaks because Git checkout on AppVeyor (or elsewhere) will adjust the line breaks var originalContent = File.ReadAllText(fileName); File.WriteAllText(fileName, originalContent.Replace(Environment.NewLine, "\n")); _objectUnderTest = Parser.Parse(fileName); _root = _objectUnderTest.Children.Single(); }
public void Xml_without_declaration_can_be_read() { var parentDirectory = Directory.GetParent(new Uri(GetType().Assembly.Location).LocalPath).FullName; var fileName = Path.Combine(parentDirectory, "Resources", "test_without_declaration.xml"); _objectUnderTest = Parser.Parse(fileName); _root = _objectUnderTest.Children.Single(); Assert.That(_objectUnderTest.LocationSpan.Start, Is.EqualTo(new LineInfo(1, 0)), "Wrong start"); Assert.That(_objectUnderTest.LocationSpan.End, Is.EqualTo(new LineInfo(28, 0)), "Wrong end"); Assert.That(_objectUnderTest.FooterSpan, Is.EqualTo(new CharacterSpan(495, 496)), "Wrong footer"); }
private static bool CreateYaml(string path, string allText, out Yaml.File yamlContent) { var lines = LineSplitter.SplitLines(allText); var file = YamlFile(lines, path); XDocument document = null; try { document = XDocument.Parse(allText, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); } catch (Exception ex) { file.ParsingErrors.Add(new ParsingError { ErrorMessage = ex.Message }); } var parsingFine = file.ParsingErrors.Count == 0; if (parsingFine) { var root = YamlRoot(lines, allText); // adjust footer var footerStart = root.FooterSpan.End + 1; var footerEnd = allText.Length - 1; if (footerStart < footerEnd) { file.FooterSpan = new CharacterSpan(footerStart, footerEnd); } YamlInfrastructureCommentAndSchema(root, lines, allText); file.Children.Add(root); root.Children.AddRange(Yaml("resheader", document, lines)); root.Children.AddRange(Yaml("data", document, lines)); root.Children.AddRange(Yaml("metadata", document, lines)); root.Children.AddRange(Yaml("assembly", document, lines)); // sort based on span root.Children.Sort(new AscendingSpanComparer()); } yamlContent = file; return(parsingFine); }
public static bool TryParseFile(string path, out Yaml.File yamlContent) { var allText = File.ReadAllText(path); if (string.IsNullOrWhiteSpace(allText)) { yamlContent = new Yaml.File { Name = path, LocationSpan = new LocationSpan(new LineInfo(0, 0), new LineInfo(0, 0)), FooterSpan = new CharacterSpan(0, -1), }; return(true); } return(CreateYaml(path, allText, out yamlContent)); }
public void Empty_file_can_be_read_without_parsing_errors() { var fileName = Path.GetTempFileName(); try { _objectUnderTest = Parser.Parse(fileName); } finally { File.Delete(fileName); } Assert.That(_objectUnderTest.LocationSpan.Start, Is.EqualTo(LineInfo.None), "Wrong start"); Assert.That(_objectUnderTest.LocationSpan.End, Is.EqualTo(LineInfo.None), "Wrong end"); Assert.That(_objectUnderTest.FooterSpan, Is.EqualTo(CharacterSpan.None), "Wrong footer"); }