Пример #1
0
        public void Snprintf()
        {
            StringBuilder s = new StringBuilder(1000);

            Stdlib.snprintf(s, "hello, %s world!\n");
            Assert.AreEqual(s.ToString(), "hello, %s world!\n",
                            "#SNPF: string not echoed");
            s = new StringBuilder(1000);
            Stdlib.snprintf(s, "yet another %s test", "simple");
            Assert.AreEqual(s.ToString(), "yet another simple test",
                            "#SNPF: string argument not printed");
            s = new StringBuilder(1000);
            string fmt =
                @"this is another test:
	  char: '%c'
	 short: %i
	   int: %i
	  long: %li
	 float: %g
	double: %g"     + "\n";

            Stdlib.snprintf(s, fmt, 'a', (short)16, 32, (long)64, (double)32.23, 64.46);
            string expected =
                @"this is another test:
	  char: 'a'
	 short: 16
	   int: 32
	  long: 64
	 float: 32.23
	double: 64.46"     + "\n";

            Assert.AreEqual(s.ToString(), expected,
                            "#SNPF: printf of many builtin types failed");
        }