示例#1
0
        public void TryGetByName_NullName_Throws()
        {
            var dictionary = new DictionaryToken(new Dictionary <IToken, IToken>());

            Action action = () => dictionary.TryGetByName(null, out var _);

            Assert.Throws <ArgumentNullException>(action);
        }
示例#2
0
        private static CharacterIdentifierSystemInfo GetCharacterIdentifier(DictionaryToken dictionary, bool isLenientParsing)
        {
            string GetErrorMessage(string missingKey)
            {
                return($"No {missingKey} found in the CIDSystemInfo dictionary: " + dictionary);
            }

            if (!dictionary.TryGetByName(CosName.REGISTRY, out var registry) || !(registry is StringToken registryString))
            {
                if (isLenientParsing)
                {
                    registryString = new StringToken("Adobe");
                }
                else
                {
                    throw new InvalidOperationException(GetErrorMessage("registry"));
                }
            }

            if (!dictionary.TryGetByName(CosName.ORDERING, out var ordering) || !(ordering is StringToken orderingString))
            {
                if (isLenientParsing)
                {
                    orderingString = new StringToken("");
                }
                else
                {
                    throw new InvalidOperationException(GetErrorMessage("ordering"));
                }
            }

            if (!dictionary.TryGetByName(CosName.SUPPLEMENT, out var supplement) || !(supplement is NumericToken supplementNumeric))
            {
                if (isLenientParsing)
                {
                    supplementNumeric = new NumericToken(0);
                }
                else
                {
                    throw new InvalidOperationException(GetErrorMessage("supplement"));
                }
            }

            return(new CharacterIdentifierSystemInfo(registryString.Data, orderingString.Data, supplementNumeric.Int));
        }
示例#3
0
        public void TryGetByName_EmptyDictionary()
        {
            var dictionary = new DictionaryToken(new Dictionary <IToken, IToken>());

            var result = dictionary.TryGetByName(CosName.ACTUAL_TEXT, out var token);

            Assert.False(result);
            Assert.Null(token);
        }
示例#4
0
        public void TryGetByName_NonEmptyDictionaryNotContainingKey()
        {
            var dictionary = new DictionaryToken(new Dictionary <IToken, IToken>
            {
                { new NameToken("Registry"), new StringToken("None") }
            });

            var result = dictionary.TryGetByName(CosName.ACTUAL_TEXT, out var token);

            Assert.False(result);
            Assert.Null(token);
        }
示例#5
0
        public void TryGetByName_ContainingKey()
        {
            var dictionary = new DictionaryToken(new Dictionary <IToken, IToken>
            {
                { new NameToken("Fish"), new NumericToken(420) },
                { new NameToken("Registry"), new StringToken("None") }
            });

            var result = dictionary.TryGetByName(CosName.REGISTRY, out var token);

            Assert.True(result);
            Assert.Equal("None", Assert.IsType <StringToken>(token).Data);
        }