string_tests.c
Go to the documentation of this file.00001
00011 #include "op_string.h"
00012
00013 #include <stdlib.h>
00014 #include <stdio.h>
00015 #include <string.h>
00016
00017 void error(char const * str)
00018 {
00019 fprintf(stderr, "%s\n", str);
00020 exit(EXIT_FAILURE);
00021 }
00022
00023
00024 int main()
00025 {
00026 if (!strisprefix("", ""))
00027 error("\"\" is not a prefix of \"\"");
00028 if (!strisprefix("a", ""))
00029 error("\"\" is not a prefix of a");
00030 if (!strisprefix("a", "a"))
00031 error("a is not a prefix of a");
00032 if (!strisprefix("aa", "a"))
00033 error("a is not a prefix of aa");
00034 if (strisprefix("a", "b"))
00035 error("b is a prefix of a");
00036
00037 if (strcmp(skip_ws(""), ""))
00038 error("skip_ws of \"\" is not \"\"");
00039 if (strcmp(skip_ws("\na"), "a"))
00040 error("skip_ws of \\na is not a");
00041 if (strcmp(skip_ws("\n\na"), "a"))
00042 error("skip_ws of \\n\\na is not a");
00043 if (strcmp(skip_ws("\n a"), "a"))
00044 error("skip_ws of \\n a is not a");
00045 if (strcmp(skip_ws("\n \ta"), "a"))
00046 error("skip_ws of \\n \\ta is not a");
00047 if (strcmp(skip_ws("\n \t"), ""))
00048 error("skip_ws of \\n \\t is not \"\"");
00049 if (strcmp(skip_ws(" "), ""))
00050 error("skip_ws of \" \" is not \"\"");
00051
00052 if (strcmp(skip_nonws(""), ""))
00053 error("skip_nonws of \"\" is not \"\"");
00054 if (strcmp(skip_nonws("a"), ""))
00055 error("skip_nonws of a is not \"\"");
00056 if (strcmp(skip_nonws("\n"), "\n"))
00057 error("skip_nonws of \\n is not \\n");
00058 if (strcmp(skip_nonws(" "), " "))
00059 error("skip_nonws of \" \" is not \" \"");
00060 if (strcmp(skip_nonws("\t"), "\t"))
00061 error("skip_nonws of \\t is not \\t");
00062 if (strcmp(skip_nonws("a\n"), "\n"))
00063 error("skip_nonws of a\\n is not \\n");
00064 if (strcmp(skip_nonws("ab"), ""))
00065 error("skip_nonws of ab is not \"\"");
00066
00067 if (!empty_line(""))
00068 error("empty_line is false for \"\"");
00069 if (!empty_line("\n\t "))
00070 error("empty_line is false for \"\\n\\n \"");
00071 if (!empty_line(" "))
00072 error("empty_line is false for \" \"");
00073 if (empty_line("\r"))
00074 error("empty_line is true for \\r");
00075
00076 if (comment_line(""))
00077 error("comment_line is true for \"\"");
00078 if (comment_line("\n"))
00079 error("comment_line is true for \n");
00080 if (!comment_line("#"))
00081 error("comment_line is false for #");
00082 if (!comment_line(" #"))
00083 error("comment_line is false for \" #\"");
00084
00085 if (!comment_line("\n#"))
00086 error("comment_line is false for \\n#");
00087 if (!comment_line("\t#"))
00088 error("comment_line is false for \\t#");
00089
00090 return EXIT_SUCCESS;
00091 }