forked from TylerBrinks/ExCSS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestExtensions.cs
More file actions
45 lines (39 loc) · 1.13 KB
/
TestExtensions.cs
File metadata and controls
45 lines (39 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using ExCSS;
namespace ExCSS.Tests
{
static class TestExtensions
{
public static Stylesheet ToCssStylesheet(this string sourceCode)
{
var parser = new StylesheetParser();
return parser.Parse(sourceCode);
}
public static IEnumerable<Comment> GetComments(this StylesheetNode node)
{
return node.GetAll<Comment>();
}
public static IEnumerable<T> GetAll<T>(this IStylesheetNode node)
where T : IStyleFormattable
{
if (node == null)
throw new ArgumentNullException(nameof(node));
if (node is T)
{
yield return (T)node;
}
foreach (var entity in node.Children.SelectMany(m => m.GetAll<T>()))
{
yield return entity;
}
}
public static Stylesheet ToCssStylesheet(this Stream content)
{
var parser = new StylesheetParser();
return parser.Parse(content);
}
}
}