예제 #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);
            });
        }
예제 #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());
        }
예제 #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();
    }
예제 #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));
            });
        }
예제 #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);
            });
        }
예제 #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());
        }
예제 #7
0
 public void ConcatCultureCodePartsTest(string languageCode, string localeCode, string expected)
 {
     CultureUtilities.ConcatCultureCodeParts(languageCode, localeCode).Should().Be(expected);
 }
예제 #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);
 }
예제 #9
0
        public void CleanCutureCodeThrowsTest(string value)
        {
            Action action = () => CultureUtilities.CleanCutureCode(value);

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

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