Exemplo n.º 1
0
        public static void ParseReturnsTheCorrectFormatString(string format, params string [] expectedArgumentHoles)
        {
            var formatString  = FormatString.Parse(format);
            var argumentHoles = formatString.ArgumentHoles
                                .Select(argumentHole => argumentHole.ToString( ))
                                .ToArray( );

            Assert.Equal(expectedArgumentHoles, argumentHoles);
        }
Exemplo n.º 2
0
        public static void SelectPluralFormsOnInvariantReturnsTheCorrectPluralForms(string format, PluralForm [] availablePluralForms, object [] arguments, PluralForm [] expectedPluralForms)
        {
            var formatString = FormatString.Parse(format);

            for (var index = 0; index < formatString.Arguments.Length; index++)
            {
                formatString.Arguments [index].AvailablePluralForms = availablePluralForms [index];
            }

            Assert.Equal(expectedPluralForms, PluralRules.Invariant.SelectPluralForms(formatString, arguments));
        }
Exemplo n.º 3
0
        protected override PluralResourceSet LoadResourceSet(PluralRules pluralRules)
        {
            var resources       = resourceManager.GetResourceSet(pluralRules.Culture, true, true);
            var pluralResources = new Dictionary <string, List <FormatString> > ( );

            var resource = resources.GetEnumerator( );

            while (resource.MoveNext( ))
            {
                if (!(resource.Value is string))
                {
                    continue;
                }

                var name     = (string)resource.Key;
                var baseName = namingStrategy.ParseArguments(pluralRules, name, out var arguments);

                if (baseName != name)
                {
                    if (!pluralResources.TryGetValue(baseName, out var pluralFormats))
                    {
                        pluralResources.Add(baseName, pluralFormats = new List <FormatString> ( ));
                    }

                    var pluralFormat = FormatString.Parse(resource.Value?.ToString( ));
                    pluralFormat.Arguments = arguments;
                    pluralFormats.Add(pluralFormat);
                }
            }

            var resourceSet = new PluralResourceSet(pluralRules, pluralResources.Count);

            foreach (var pluralResource in pluralResources)
            {
                var name  = pluralResource.Key;
                var value = resources.GetString(name);
                if (value == null)
                {
                    continue;
                }

                var defaultFormat = FormatString.Parse(value);
                var pluralFormats = pluralResource.Value.ToArray( );

                resourceSet.Add(name, new PluralFormatString(defaultFormat, pluralFormats));
            }

            return(resourceSet);
        }
Exemplo n.º 4
0
        private int GetNumberOfArguments(IResource resource)
        {
            if (resource.Type != TypeNames.String)
            {
                return(0);
            }

            try
            {
                var formatString      = FormatString.Parse((string)resource.Value);
                var numberOfArguments = formatString.ArgumentHoles
                                        .Select(argumentHole => argumentHole.Index)
                                        .DefaultIfEmpty(-1)
                                        .Max( ) + 1;
                return(numberOfArguments);
            }
            catch (FormatException exception)
            {
                AddError(resource, Format(ErrorInStringResourceFormat, exception.Message, resource.Name));
            }

            return(0);
        }
Exemplo n.º 5
0
        public static void ParseThrowsTheCorrectFormatException(string format, string expectedError)
        {
            var exception = Assert.Throws <FormatException> (() => FormatString.Parse(format));

            Assert.Equal(expectedError, exception.Message);
        }
Exemplo n.º 6
0
 public void ParseThrowsOnNull( )
 {
     Assert.Throws <ArgumentNullException> (() => FormatString.Parse(null));
 }