public void ParseMethodTest() { // ARRANGE var text = @"<!DOCTYPE html> <html> <head> <title>Hello</title> </head> <body> <p>Hello, world. </body> </html>"; // ACT var contents = HtmlSyntaxParser.Parse(text); // ASSERT Assert.AreEqual("Hello, world.", contents["html"]["body"]["p"].Contents.Text); }
// ---------------------------------------------------------------------------------------------------- // Pre-Processing Operations // ---------------------------------------------------------------------------------------------------- // (None) // ---------------------------------------------------------------------------------------------------- // Input Processing Operations // ---------------------------------------------------------------------------------------------------- protected override void ProcessRecord() { if (this.ParameterSetName == "Path") { foreach (var filepath in SessionLocation.GetResolvedPath(this.SessionState, this.Path)) { // Validation (File Existence Check): if (!File.Exists(filepath)) { throw new FileNotFoundException(); } // Should Process if (this.ShouldProcess($"ファイル '{filepath}'", "HTML コンテンツの構文解析")) { // GET Parsed HTML Contents var contents = HtmlSyntaxParser.Read(filepath, this.Encoding); // OUTPUT HTML Contents this.WriteContents(contents); } } } else if (this.ParameterSetName == "InputObject") { // Should Process if (this.ShouldProcess($"入力文字列", "HTML コンテンツの構文解析")) { // GET Parsed HTML Contents var contents = HtmlSyntaxParser.Parse(this.InputObject); // OUTPUT HTML Contents this.WriteContents(contents); } } else { throw new InvalidOperationException(); } }
public void ReadMethodTest(string input, string expected, string encodingName) { // [NOTE] // Nuget Package "System.Text.Encoding.CodePages" is required for "shift_jis" encoding. // And, the following code is required. Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); // ARRANGE var encoding = string.IsNullOrEmpty(encodingName) ? Encoding.UTF8 : Encoding.GetEncoding(encodingName); var path = $@"./{nameof(HtmlSyntaxParser)}.{nameof(ReadMethodTest)} {encoding.EncodingName}.html"; // ARRANGE (Create File) File.WriteAllText(path, input, encoding); // ACT var contents = encoding is null? HtmlSyntaxParser.Read(path) : HtmlSyntaxParser.Read(path, encoding); // ASSERT Assert.AreEqual(expected, contents["html"]["body"]["p"].Contents.Text); }
public void RemoveCommentMethodTest(string input, string expected) { Assert.AreEqual(expected, HtmlSyntaxParser.RemoveComment(input)); }