Exemple #1
0
        public void Compile_ForAllFoundTutorials_Succeeds(
            [ValueSource(nameof(Tutorials))] Tutorial tutorial,
            [ValueSource(nameof(Cultures))] string culture)
        {
            CultureUtilities.WithCulture(culture, () =>
            {
                var grammar = new PegParser().Parse(tutorial.GrammarText);

                var result = PegCompiler.Compile(grammar);

                Assert.That(result.Errors, Is.Empty);
            });
        }
Exemple #2
0
        public void TestTimes()
        {
            CultureUtilities.ForceCulture();
            var log = Logger.LogToStringBuilder();

            Logger.UseTimer(new MockTimer());
            Logger.Show(timestamp: true, timeDifference: true);
            Logger.Variable("name", "Llewellyn");
            Logger.Variable("name", "Llewellyn");
            Logger.Variable("name", "Llewellyn");

            Approvals.Verify(log.ToString());
        }
Exemple #3
0
    private void PopulateDropDown()
    {
        uxNameDrop.DataSource     = CultureUtilities.GetCultureList();
        uxNameDrop.DataTextField  = "CultureName";
        uxNameDrop.DataValueField = "Language-Region";
        uxNameDrop.DataBind();
        uxNameDrop.Items.Insert(0, new ListItem("Select Culture", ""));
        uxNameDrop.SelectedIndex = 0;

        uxDisplayNameBaseDrop.DataSource     = DataAccessContext.CultureRepository.GetAll();
        uxDisplayNameBaseDrop.DataTextField  = "DisplayName";
        uxDisplayNameBaseDrop.DataValueField = "CultureID";
        uxDisplayNameBaseDrop.DataBind();
    }
Exemple #4
0
        public void Parse_For05Calculator_ThrowsForInvalidFormats(
            [Values("5,7+8,9*42")] string expression,
            [ValueSource(nameof(Cultures))] string culture)
        {
            CultureUtilities.WithCulture(culture, () =>
            {
                var tutorial = Tutorial.FindAll().Single(t => t.Name == "05 - Calculator");
                var grammar  = new PegParser().Parse(tutorial.GrammarText);
                var compiled = PegCompiler.Compile(grammar);
                var parser   = CodeCompiler.Compile <object>(compiled);

                Assert.Throws <FormatException>(() => parser.Parse(expression));
            });
        }
Exemple #5
0
        public void Parse_ForAllFoundTutorials_Succeeds(
            [ValueSource(nameof(Tutorials))] Tutorial tutorial,
            [ValueSource(nameof(Cultures))] string culture)
        {
            CultureUtilities.WithCulture(culture, () =>
            {
                var grammar  = new PegParser().Parse(tutorial.GrammarText);
                var compiled = PegCompiler.Compile(grammar);
                var parser   = CodeCompiler.Compile <object>(compiled);

                var result = parser.Parse(tutorial.TestText);

                Assert.That(result, Is.Not.Null);
            });
        }
Exemple #6
0
        private static List <string> GetUserCulturesName(IEnumerable <string> userLanguages)
        {
            List <string> userCultures = new List <string>();

            foreach (string language in userLanguages ?? Enumerable.Empty <string>())
            {
                CultureInfo contextCulture = CultureUtilities.TryCreateSpecificCulture(language);
                if (contextCulture == null)
                {
                    continue;
                }
                userCultures.Add(contextCulture.Name);
            }
            return(userCultures.Distinct().ToList());
        }
Exemple #7
0
 public void ConcatCultureCodePartsTest(string languageCode, string localeCode, string expected)
 {
     CultureUtilities.ConcatCultureCodeParts(languageCode, localeCode).Should().Be(expected);
 }
Exemple #8
0
 public void SplitCultureCodePartsTest(string value, string expectedLanguageCode, string expectedLocaleCode)
 {
     var(languageCode, localeCode) = CultureUtilities.SplitCultureCodeParts(value);
     languageCode.Should().Be(expectedLanguageCode);
     localeCode.Should().Be(expectedLocaleCode);
 }
Exemple #9
0
        public void CleanCutureCodeThrowsTest(string value)
        {
            Action action = () => CultureUtilities.CleanCutureCode(value);

            action.Should().Throw <ArgumentException>();
        }
Exemple #10
0
        public void CleanCutureCodeTest(string value, string expected)
        {
            var actual = CultureUtilities.CleanCutureCode(value);

            actual.Should().Be(expected);
        }