hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

entries+test.ha (1547B)


      1 // SPDX-License-Identifier: MPL-2.0
      2 // (c) Hare authors <https://harelang.org>
      3 
      4 const text_plain: mimetype = mimetype {
      5 	mime = "text/plain",
      6 	exts = ["txt"],
      7 };
      8 
      9 const text_hare: mimetype = mimetype {
     10 	mime = "text/x-hare",
     11 	exts = ["ha"],
     12 };
     13 
     14 @init fn init() void = {
     15 	register(&text_plain, &text_hare);
     16 };
     17 
     18 @test fn lookup_mime() void = {
     19 	assert(lookup_mime("foo/bar") == null);
     20 
     21 	const result = lookup_mime("text/plain") as *mimetype;
     22 	assert(result.mime == "text/plain");
     23 	assert(len(result.exts) >= 1);
     24 
     25 	let extfound = false;
     26 	for (let ext .. result.exts) {
     27 		if (ext == "txt") {
     28 			extfound = true;
     29 		};
     30 	};
     31 	assert(extfound);
     32 
     33 	const result = lookup_mime("text/x-hare") as *mimetype;
     34 	assert(result.mime == "text/x-hare");
     35 	assert(len(result.exts) >= 1);
     36 
     37 	let extfound = false;
     38 	for (let ext .. result.exts) {
     39 		if (ext == "ha") {
     40 			extfound = true;
     41 		};
     42 	};
     43 	assert(extfound);
     44 };
     45 
     46 
     47 @test fn lookup_ext() void = {
     48 	assert(lookup_ext("foo") == null);
     49 	assert(lookup_ext(".foo") == null);
     50 
     51 	const result = lookup_ext("txt") as *mimetype;
     52 	assert(result.mime == "text/plain");
     53 
     54 	let extfound = false;
     55 	for (let ext .. result.exts) {
     56 		if (ext == "txt") {
     57 			extfound = true;
     58 		};
     59 	};
     60 	assert(extfound);
     61 
     62 	const result = lookup_ext(".txt") as *mimetype;
     63 	assert(result.mime == "text/plain");
     64 
     65 	const result = lookup_ext("ha") as *mimetype;
     66 	assert(result.mime == "text/x-hare");
     67 	assert(len(result.exts) >= 1);
     68 
     69 	let extfound = false;
     70 	for (let ext .. result.exts) {
     71 		if (ext == "ha") {
     72 			extfound = true;
     73 		};
     74 	};
     75 	assert(extfound);
     76 };