public void TestEncoding()
        {
            var translator = new AsmEncoding();

            translator.SelectEncoding("petscii");
            translator.Map("az", 'A');
            translator.Map("AZ", 'a');

            var expected   = Encoding.ASCII.GetBytes("hELLO, World");
            var transbytes = translator.GetBytes("Hello, wORLD");

            Assert.AreEqual(expected, transbytes);

            translator.SelectEncoding("cbmscreen");
            translator.Map('@', '\0');
            translator.Map("az", Convert.ToChar(1));

            expected = expected.Select(delegate(byte b)
            {
                if (b == '@' || (b >= 'a' && b <= 'z'))
                {
                    b -= 0x60;
                }
                return(b);
            }).ToArray();

            transbytes = translator.GetBytes("hELLO, World").ToArray();

            Assert.AreEqual(expected, transbytes);

            expected = Encoding.ASCII.GetBytes("Hello, World!");

            translator.SelectEncoding("none");
            transbytes = translator.GetBytes("Hello, World!");
            Assert.AreEqual(expected, transbytes);

            expected = Encoding.ASCII.GetBytes("\t\t\"'");
            expected = expected.Select(delegate(byte b)
            {
                if (b == '\t')
                {
                    return((byte)14);
                }
                return(b);
            }).ToArray();

            translator.SelectEncoding("escapeclub");
            translator.Map('\t', 14);
            transbytes = translator.GetBytes("\t\t\"'");
            Assert.AreEqual(expected, transbytes);

            expected = new byte[] { 0x9f };
            translator.Map('\u21d4', 0x9f);
            transbytes = translator.GetBytes("\u21d4");
            Assert.AreEqual(expected, transbytes);
        }
Beispiel #2
0
        /// <summary>
        /// Initialize the static members of this instance.
        /// </summary>
        public static void Initialize()
        {
            Options = new AsmCommandLineOptions();

            Evaluator = new Evaluator(false);

            Encoding = new AsmEncoding(false);

            Output = new Compilation();

            Symbols = new SymbolManager();

            Log = new ErrorLog();
        }
Beispiel #3
0
        /// <summary>
        /// Initialize the static members of this instance. The specified args
        /// passed will re-initialize the common Options object.
        /// </summary>
        /// <param name="args">The commandline arguments.</param>
        public static void Initialize(string[] args)
        {
            Options = new AsmCommandLineOptions();

            Options.ParseArgs(args);

            Evaluator = new Evaluator(Options.CaseSensitive);

            Encoding = new AsmEncoding(Options.CaseSensitive);

            Output = new Compilation();

            Symbols = new SymbolManager();

            Log = new ErrorLog();
        }
        public void TestEncodingGetChar()
        {
            var encoding = new AsmEncoding();

            encoding.SelectEncoding("test");
            string teststring    = "τϵστ";
            var    testbytes     = encoding.GetBytes(teststring);
            var    expectedbytes = Encoding.UTF8.GetBytes(teststring);

            Assert.AreEqual(expectedbytes, testbytes);

            var testchars     = encoding.GetChars(testbytes);
            var expectedchars = Encoding.UTF8.GetChars(expectedbytes);

            Assert.AreEqual(expectedchars, testchars);

            var testcharcount     = encoding.GetChars(testbytes, 0, testbytes.Length, testchars, 0);
            var expectedcharcount = Encoding.UTF8.GetChars(expectedbytes, 0, expectedbytes.Length, expectedchars, 0);

            Assert.AreEqual(expectedcharcount, testcharcount);

            encoding.Map('τ', 0xff);
            expectedbytes = new byte[] { 0xff, 207, 181, 207, 131, 0xff };
            testbytes     = encoding.GetBytes(teststring);

            Assert.AreEqual(expectedbytes, testbytes);
            testchars = encoding.GetChars(testbytes);
            Assert.AreEqual(expectedchars, testchars);

            testcharcount = encoding.GetChars(testbytes, 0, testbytes.Length, testchars, 0);
            Assert.AreEqual(expectedcharcount, testcharcount);

            encoding.Unmap("τ");
            expectedbytes = Encoding.UTF8.GetBytes(teststring);
            testbytes     = encoding.GetBytes(teststring);
            Assert.AreEqual(expectedbytes, testbytes);

            testchars = encoding.GetChars(testbytes);
            Assert.AreEqual(expectedchars, testchars);

            testcharcount = encoding.GetChars(testbytes, 0, testbytes.Length, testchars, 0);
            Assert.AreEqual(expectedcharcount, testcharcount);
        }
        public void TestEmojis()
        {
            var    encoding      = new AsmEncoding();
            string smiley        = "😀";                                   // smiley face
            var    expectedbytes = new byte[] { 0xF0, 0x9F, 0x98, 0x80 }; // utf-8 encoding of U+1F600
            var    testbytes     = encoding.GetBytes(smiley);

            Assert.AreEqual(expectedbytes, testbytes);

            encoding.SelectEncoding("emojis");
            encoding.Map("😀", 204);
            expectedbytes = new byte[] { 204 };
            testbytes     = encoding.GetBytes(smiley);
            Assert.AreEqual(expectedbytes, testbytes);

            encoding.SelectDefaultEncoding();

            var expectedchars = smiley.ToCharArray();
            var testchars     = encoding.GetChars(new byte[] { 0xF0, 0x9F, 0x98, 0x80 });

            Assert.AreEqual(expectedchars, testchars);
        }
        public TestController(string[] args)
        {
            Output = new Compilation(true);

            Options = new AsmCommandLineOptions();

            Log = new ErrorLog();

            Evaluator = new Evaluator();

            Encoding = new AsmEncoding();

            Evaluator.DefineSymbolLookup(@"(?<=\B)'(.+)'(?=\B)", GetCharValue);

            Evaluator.DefineSymbolLookup(@"(?<=^|[^a-zA-Z0-9_.$])(?>(_+[a-zA-Z0-9]|[a-zA-Z])(\.[a-zA-Z_]|[a-zA-Z0-9_])*)(?=[^(.]|$)", GetSymbol);

            if (args != null)
            {
                Options.ProcessArgs(args);
            }
            Symbols = new SymbolManager(this);
        }