[m-rev.] diff: test case for non-ASCII input

Zoltan Somogyi zs at cs.mu.OZ.AU
Fri Nov 5 14:11:58 AEDT 2004


Add a test for the ability of read_line_as_string and read_char to handle
non-ASCII characters, following a bug report on mercury-users.

tests/hard_coded/nonascii.{m,exp}:
	New test case that reads characters and echoes them. To make the
	output ASCII (and thus acceptable to diff) even if the input isn't,
	the echoing converts each char to an int.

tests/hard_coded/nonascii_gen.c:
	A small C program to generate the non-ASCII input data for
	nonascii.m.

tests/hard_coded/Mmakefile:
	Add the rules necessary to create nonascii.m's input before it is run,
	and enable the new test case.

Zoltan.

cvs diff: Diffing .
Index: Mmakefile
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/hard_coded/Mmakefile,v
retrieving revision 1.238
diff -u -b -r1.238 Mmakefile
--- Mmakefile	8 Oct 2004 07:01:28 -0000	1.238
+++ Mmakefile	4 Nov 2004 06:40:47 -0000
@@ -116,6 +116,7 @@
 	no_inline \
 	no_inline_builtins \
 	no_warn_singleton \
+	nonascii \
 	nondet_ctrl_vn \
 	nondet_copy_out \
 	nullary_ho_func \
@@ -477,6 +478,14 @@
 mapped_module.depend: Mercury.modules
 
 #-----------------------------------------------------------------------------#
+
+nonascii.out:	nonascii.data
+
+nonascii.data:	nonascii_gen
+	nonascii_gen > nonascii.data
+
+nonascii_gen:	nonascii_gen.c
+	$(CC) nonascii_gen.c -o nonascii_gen
 
 # no_fully_strict is expected to fail (it calls error/1).
 # We also need to pipe the output through sed to avoid hard-coding
Index: nonascii.exp
===================================================================
RCS file: nonascii.exp
diff -N nonascii.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ nonascii.exp	4 Nov 2004 03:14:35 -0000
@@ -0,0 +1,510 @@
+1,
+2,
+3,
+4,
+5,
+6,
+7,
+8,
+9,
+11,
+12,
+13,
+14,
+15,
+16,
+17,
+18,
+19,
+20,
+21,
+22,
+23,
+24,
+25,
+26,
+27,
+28,
+29,
+30,
+31,
+32,
+33,
+34,
+35,
+36,
+37,
+38,
+39,
+40,
+41,
+42,
+43,
+44,
+45,
+46,
+47,
+48,
+49,
+50,
+51,
+52,
+53,
+54,
+55,
+56,
+57,
+58,
+59,
+60,
+61,
+62,
+63,
+64,
+65,
+66,
+67,
+68,
+69,
+70,
+71,
+72,
+73,
+74,
+75,
+76,
+77,
+78,
+79,
+80,
+81,
+82,
+83,
+84,
+85,
+86,
+87,
+88,
+89,
+90,
+91,
+92,
+93,
+94,
+95,
+96,
+97,
+98,
+99,
+100,
+101,
+102,
+103,
+104,
+105,
+106,
+107,
+108,
+109,
+110,
+111,
+112,
+113,
+114,
+115,
+116,
+117,
+118,
+119,
+120,
+121,
+122,
+123,
+124,
+125,
+126,
+127,
+128,
+129,
+130,
+131,
+132,
+133,
+134,
+135,
+136,
+137,
+138,
+139,
+140,
+141,
+142,
+143,
+144,
+145,
+146,
+147,
+148,
+149,
+150,
+151,
+152,
+153,
+154,
+155,
+156,
+157,
+158,
+159,
+160,
+161,
+162,
+163,
+164,
+165,
+166,
+167,
+168,
+169,
+170,
+171,
+172,
+173,
+174,
+175,
+176,
+177,
+178,
+179,
+180,
+181,
+182,
+183,
+184,
+185,
+186,
+187,
+188,
+189,
+190,
+191,
+192,
+193,
+194,
+195,
+196,
+197,
+198,
+199,
+200,
+201,
+202,
+203,
+204,
+205,
+206,
+207,
+208,
+209,
+210,
+211,
+212,
+213,
+214,
+215,
+216,
+217,
+218,
+219,
+220,
+221,
+222,
+223,
+224,
+225,
+226,
+227,
+228,
+229,
+230,
+231,
+232,
+233,
+234,
+235,
+236,
+237,
+238,
+239,
+240,
+241,
+242,
+243,
+244,
+245,
+246,
+247,
+248,
+249,
+250,
+251,
+252,
+253,
+254,
+255,
+10
+1
+2
+3
+4
+5
+6
+7
+8
+9
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+30
+31
+32
+33
+34
+35
+36
+37
+38
+39
+40
+41
+42
+43
+44
+45
+46
+47
+48
+49
+50
+51
+52
+53
+54
+55
+56
+57
+58
+59
+60
+61
+62
+63
+64
+65
+66
+67
+68
+69
+70
+71
+72
+73
+74
+75
+76
+77
+78
+79
+80
+81
+82
+83
+84
+85
+86
+87
+88
+89
+90
+91
+92
+93
+94
+95
+96
+97
+98
+99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+10
Index: nonascii.m
===================================================================
RCS file: nonascii.m
diff -N nonascii.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ nonascii.m	4 Nov 2004 01:57:06 -0000
@@ -0,0 +1,68 @@
+% This is a regression test for bugs relating to handling of non-ASCII
+% characters.
+
+:- module nonascii.
+
+:- interface.
+
+:- import_module io.
+
+:- pred main(io::di, io::uo) is det.
+
+:- implementation.
+
+:- import_module int, char, string, list.
+
+main(!IO) :-
+	io__open_input("nonascii.data", Result, !IO),
+	(
+		Result = ok(Stream),
+		test1(Stream, !IO),
+		test2(Stream, 255, !IO)
+	;
+		Result = error(Error),
+		io__error_message(Error, Msg),
+		io__write_string(Msg, !IO)
+	).
+
+:- pred test1(io__input_stream::in, io::di, io::uo) is det.
+
+test1(Stream, !IO) :-
+	io__read_line_as_string(Stream, Result, !IO),
+	(
+		Result = ok(Line),
+		Chars = string__to_char_list(Line),
+		Ints = list__map(char__to_int, Chars),
+		io__write_list(Ints, ",\n", io__write_int, !IO),
+		io__nl(!IO)
+	;
+		Result = eof,
+		io__write_string("premature EOF\n", !IO)
+	;
+		Result = error(Error),
+		io__error_message(Error, Msg),
+		io__write_string(Msg, !IO)
+	).
+
+:- pred test2(io__input_stream::in, int::in, io::di, io::uo) is det.
+
+test2(Stream, N, !IO) :-
+	( N > 0 ->
+		io__read_char(Stream, Result, !IO),
+		(
+			Result = ok(Char),
+			Int = char__to_int(Char),
+			io__write_int(Int, !IO),
+			io__nl(!IO)
+		;
+			Result = eof,
+			io__write_string("premature EOF\n", !IO)
+		;
+			Result = error(Error),
+			io__error_message(Error, Msg),
+			io__write_string(Msg, !IO)
+		),
+		test2(Stream, N - 1, !IO)
+	;
+		true
+	).
Index: nonascii_gen.c
===================================================================
RCS file: nonascii_gen.c
diff -N nonascii_gen.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ nonascii_gen.c	5 Nov 2004 02:27:43 -0000
@@ -0,0 +1,24 @@
+#include <stdio.h>
+
+int
+main(void)
+{
+	int	i;
+
+	for (i = 1; i < 256; i++) {
+		if (i != '\n') {
+			putchar(i);
+		}
+	}
+
+	putchar('\n');
+
+	for (i = 1; i < 256; i++) {
+		if (i != '\n') {
+			putchar(i);
+		}
+	}
+
+	putchar('\n');
+	return 0;
+}
cvs diff: Diffing exceptions
cvs diff: Diffing purity
cvs diff: Diffing sub-modules
cvs diff: Diffing typeclasses
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list