<commit_before>﻿using AgateLib.ApplicationModels;
using AgateLib.Geometry;
using AgateLib.IO;
using AgateLib.Testing.Fakes;
using AgateLib.UnitTesting;
using AgateLib.UserInterface.Css.Binders;
using AgateLib.UserInterface.Css.Documents;
using AgateLib.UserInterface.Css.Selectors;
using AgateLib.UserInterface.Widgets;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AgateLib.UserInterface.Css.Tests
{
	[TestClass]
	public class CssParseTest : CssTestBase
	{
		[TestInitialize]
		public void Init()
		{
			Core.Initialize(new FakeAgateFactory());
			Core.InitAssetLocations(new AssetLocations());
		}

		[TestMethod]
		public void TokenizerTest()
		{
			var tokens = CssParser.TokenizeCss("sample { test: 14em; }");

			Assert.AreEqual("sample", tokens[0].Value);
			Assert.AreEqual(CssTokenType.Identifier, tokens[0].TokenType);
			Assert.AreEqual(CssTokenType.Whitespace, tokens[1].TokenType);
			Assert.AreEqual(CssTokenType.BlockOpen, tokens[2].TokenType);
			Assert.AreEqual(CssTokenType.Whitespace, tokens[3].TokenType);
			Assert.AreEqual("test", tokens[4].Value);
			Assert.AreEqual(CssTokenType.Colon, tokens[5].TokenType);
			Assert.AreEqual(CssTokenType.Whitespace, tokens[6].TokenType);
			Assert.AreEqual("14em", tokens[7].Value);
			Assert.AreEqual(CssTokenType.SemiColon, tokens[8].TokenType);
		}

		[TestMethod]
		public void TokenizerTestID()
		{
			var tokens = CssParser.TokenizeCss("sample#ident { test: 14em; }");

			Assert.AreEqual("sample#ident", tokens[0].Value);
			Assert.AreEqual(CssTokenType.Identifier, tokens[0].TokenType);
			Assert.AreEqual(CssTokenType.BlockOpen, tokens[2].TokenType);
			Assert.AreEqual("test", tokens[4].Value);
			Assert.AreEqual(CssTokenType.Colon, tokens[5].TokenType);
			Assert.AreEqual("14em", tokens[7].Value);
			Assert.AreEqual(CssTokenType.SemiColon, tokens[8].TokenType);
		}

		[TestMethod]
		public void DistanceParser()
		{
			var result = CssDistance.FromString("3px");
			Assert.AreEqual(DistanceUnit.Pixels, result.DistanceUnit);
			Assert.AreEqual(3, result.Amount);

			result = CssDistance.FromString("3.8%");
			Assert.AreEqual(DistanceUnit.Percent, result.DistanceUnit);
			Assert.AreEqual(3.8, result.Amount);

			result = CssDistance.FromString("1.2em");
			Assert.AreEqual(DistanceUnit.FontHeight, result.DistanceUnit);
			Assert.AreEqual(1.2, result.Amount);

			CssDistanceAssert("0");
			CssDistanceAssert("3px");
			CssDistanceAssert("3.8%");
			CssDistanceAssert("1.2em");
			CssDistanceAssert("auto");
		}

		[TestMethod]
		public void DocumentWithMedia()
		{
			CssDocument doc = CssDocument.FromText("window { color: red; } @media phone { label { color: green; } label#step1 { color: black } }");

			var medium = doc.DefaultMedium;
			var style = medium.RuleBlocks.First();

			Assert.AreEqual("window", style.Selector.Text);
			Assert.AreEqual("red", style.Properties["color"]);

			medium = doc.Media.First(x => x.Text == "phone");

			style = medium.RuleBlocks.First(x => x.Selector.Text == "label");
			Assert.AreEqual("green", style.Properties["color"]);

			style = medium.RuleBlocks.First(x => x.Selector.Text == "label#step1");
			Assert.AreEqual("black", style.Properties["color"]);
		}


<commit_msg>Remove redundant test initializer.<commit_after>﻿using AgateLib.ApplicationModels;
using AgateLib.Geometry;
using AgateLib.IO;
using AgateLib.Testing.Fakes;
using AgateLib.UnitTesting;
using AgateLib.UserInterface.Css.Binders;
using AgateLib.UserInterface.Css.Documents;
using AgateLib.UserInterface.Css.Selectors;
using AgateLib.UserInterface.Widgets;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AgateLib.UserInterface.Css.Tests
{
	[TestClass]
	public class CssParseTest : CssTestBase
	{
		[TestMethod]
		public void TokenizerTest()
		{
			var tokens = CssParser.TokenizeCss("sample { test: 14em; }");

			Assert.AreEqual("sample", tokens[0].Value);
			Assert.AreEqual(CssTokenType.Identifier, tokens[0].TokenType);
			Assert.AreEqual(CssTokenType.Whitespace, tokens[1].TokenType);
			Assert.AreEqual(CssTokenType.BlockOpen, tokens[2].TokenType);
			Assert.AreEqual(CssTokenType.Whitespace, tokens[3].TokenType);
			Assert.AreEqual("test", tokens[4].Value);
			Assert.AreEqual(CssTokenType.Colon, tokens[5].TokenType);
			Assert.AreEqual(CssTokenType.Whitespace, tokens[6].TokenType);
			Assert.AreEqual("14em", tokens[7].Value);
			Assert.AreEqual(CssTokenType.SemiColon, tokens[8].TokenType);
		}

		[TestMethod]
		public void TokenizerTestID()
		{
			var tokens = CssParser.TokenizeCss("sample#ident { test: 14em; }");

			Assert.AreEqual("sample#ident", tokens[0].Value);
			Assert.AreEqual(CssTokenType.Identifier, tokens[0].TokenType);
			Assert.AreEqual(CssTokenType.BlockOpen, tokens[2].TokenType);
			Assert.AreEqual("test", tokens[4].Value);
			Assert.AreEqual(CssTokenType.Colon, tokens[5].TokenType);
			Assert.AreEqual("14em", tokens[7].Value);
			Assert.AreEqual(CssTokenType.SemiColon, tokens[8].TokenType);
		}

		[TestMethod]
		public void DistanceParser()
		{
			var result = CssDistance.FromString("3px");
			Assert.AreEqual(DistanceUnit.Pixels, result.DistanceUnit);
			Assert.AreEqual(3, result.Amount);

			result = CssDistance.FromString("3.8%");
			Assert.AreEqual(DistanceUnit.Percent, result.DistanceUnit);
			Assert.AreEqual(3.8, result.Amount);

			result = CssDistance.FromString("1.2em");
			Assert.AreEqual(DistanceUnit.FontHeight, result.DistanceUnit);
			Assert.AreEqual(1.2, result.Amount);

			CssDistanceAssert("0");
			CssDistanceAssert("3px");
			CssDistanceAssert("3.8%");
			CssDistanceAssert("1.2em");
			CssDistanceAssert("auto");
		}

		[TestMethod]
		public void DocumentWithMedia()
		{
			CssDocument doc = CssDocument.FromText("window { color: red; } @media phone { label { color: green; } label#step1 { color: black } }");

			var medium = doc.DefaultMedium;
			var style = medium.RuleBlocks.First();

			Assert.AreEqual("window", style.Selector.Text);
			Assert.AreEqual("red", style.Properties["color"]);

			medium = doc.Media.First(x => x.Text == "phone");

			style = medium.RuleBlocks.First(x => x.Selector.Text == "label");
			Assert.AreEqual("green", style.Properties["color"]);

			style = medium.RuleBlocks.First(x => x.Selector.Text == "label#step1");
			Assert.AreEqual("black", style.Properties["color"]);
		}

{'fraction_non_alphanumeric': 0.14703182374541005, 'fraction_numerical': 0.013157894736842105, 'mean_word_length': 5.297687861271676, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '371064', 'n_tokens_mistral': 2416, 'n_tokens_neox': 2152, 'n_words': 331}