Пример #1
0
        public void ReadForm_HashTable_HandlesStringAndKeywordKeys()
        {
            var input = "{\":k\" 1 :k 2}";

            var reader = Reader.ReadStr(input);

            var expected = new MalHashTable();

            expected.Add(new MalString(":k"), new MalAtom("1"));
            expected.Add(new MalKeyword(":k"), new MalAtom("2"));

            var result = Reader.ReadForm(reader);

            result.Should().BeOfType <MalHashTable>();
            result.Should().BeEquivalentTo(expected);
        }
Пример #2
0
        private static MalHashTable ReadHashTable(Reader reader)
        {
            reader.Next(); // Drop the bracket
            var list = new List <MalType>();

            while (reader.Peek() != "}")
            {
                list.Add(ReadForm(reader));
            }
            reader.Next(); // Drop the brace

            var hashTable = new MalHashTable();

            foreach (var chunk in list.Batch(2))
            {
                try
                {
                    var key = chunk.ElementAt(0);
                    var val = chunk.ElementAt(1);
                    hashTable.Add(key as IMalHashKey, val);
                }
                catch (ArgumentOutOfRangeException)
                {
                    throw new EofException();
                }
            }

            return(hashTable);
        }
Пример #3
0
        public void ReadForm_HashTable_Read()
        {
            var input = "{\"k\" 1}";

            var reader = Reader.ReadStr(input);

            var expected = new MalHashTable();

            expected.Add(new MalString("k"), new MalAtom("1"));

            var result = Reader.ReadForm(reader);

            result.Should().BeOfType <MalHashTable>();
            result.Should().BeEquivalentTo(expected);
        }