Skip to content

Commit

Permalink
Merge pull request #50 from Andrew1Medvedev/update-theme
Browse files Browse the repository at this point in the history
Add Theme name
  • Loading branch information
danipen authored May 5, 2023
2 parents 7066e69 + c110511 commit 0a9d0d6
Show file tree
Hide file tree
Showing 13 changed files with 771 additions and 31 deletions.
44 changes: 44 additions & 0 deletions src/TextMateSharp.Grammars.Tests/GrammarTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,49 @@ public void Assert_Every_Grammar_Parses_A_Line()
}
}
}

[Test]
public void Assert_Every_Grammar_With_Language_Configuration_File_Has_Language_Configuration()
{
RegistryOptions options = new RegistryOptions(ThemeName.Light);

foreach (var language in options.GetAvailableLanguages())
{
try
{
if (!string.IsNullOrEmpty(language.ConfigurationFile))
{
Assert.That(language.Configuration, Is.Not.Null);
}
}
catch (Exception ex)
{
Assert.Fail(
string.Format("[{0} grammar]: {1}", language.Id, ex.Message));
}
}
}

[Test]
public void Assert_Every_Grammar_With_Snippets_Can_Load_Snippets()
{
RegistryOptions options = new RegistryOptions(ThemeName.Light);

foreach (var grammarDefinition in options.GetAvailableGrammarDefinitions())
{
try
{
if (grammarDefinition.Contributes == null || grammarDefinition.Contributes.Snippets == null)
continue;

Assert.That(grammarDefinition.LanguageSnippets, Is.Not.Null);
}
catch (Exception ex)
{
Assert.Fail(
string.Format("[{0} grammar definition]: {1}", grammarDefinition.Name, ex.Message));
}
}
}
}
}
46 changes: 46 additions & 0 deletions src/TextMateSharp.Grammars.Tests/ThemeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;

using NUnit.Framework;
using TextMateSharp.Themes;

namespace TextMateSharp.Grammars.Tests
{
public class ThemeTests
{
[Test]
public void Assert_Every_Theme_Can_Be_Parsed()
{
RegistryOptions options = new RegistryOptions(ThemeName.Light);

foreach (var themeName in Enum.GetValues<ThemeName>())
{
try
{
IRawTheme theme = options.LoadTheme(themeName);
Assert.That(theme.GetTokenColors(), Has.Count, "Failed: " + themeName);
}
catch (Exception ex)
{
Assert.Fail(
string.Format("[{0} theme]: {1}", themeName, ex.Message));
}
}
}

[Test]
public void Theme_Match_Should_Add_Rule_Names()
{
RegistryOptions options = new RegistryOptions(ThemeName.DarkPlus);

Registry.Registry registry = new Registry.Registry(options);

Theme theme = registry.GetTheme();

var rule = theme.Match(new List<string>() { "source.cs", "keyword.other.using.cs" });

Assert.That(rule.Count, Is.GreaterThan(0));
Assert.That(rule[0].name, Is.Not.Null.Or.Empty);
}
}
}
8 changes: 7 additions & 1 deletion src/TextMateSharp.Grammars/GrammarDefinition.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
using System.Collections.Generic;
using System.IO;
using System.Text.Json;
using System.Text.Json.Serialization;

using TextMateSharp.Grammars.Resources;

namespace TextMateSharp.Grammars
{
public class Engines
Expand All @@ -24,7 +28,8 @@ public class Language
[JsonPropertyName("aliases")]
public List<string> Aliases { get; set; }
[JsonPropertyName("configuration")]
public string Configuration { get; set; }
public string ConfigurationFile { get; set; }
public LanguageConfiguration Configuration {get; set;}

public override string ToString()
{
Expand Down Expand Up @@ -93,5 +98,6 @@ public class GrammarDefinition
public Contributes Contributes { get; set; }
[JsonPropertyName("repository")]
public Repository Repository { get; set; }
public LanguageSnippets LanguageSnippets { get; set; }
}
}
Loading

0 comments on commit 0a9d0d6

Please sign in to comment.