interplane.Get Omega
Read in your language

omega-mp4

omega-mp4: ovideo, an MP4 reader written in Omega (Apache-2.0)

Brought by drakestapleton

branch main Branches Tags History

omega-mp4 / tests / docs.om

1070 lines · 17576 bytes Raw Blame History
1om2
2note tests/docs.om: publication checks of this repository's own text (README, sources, corpus notes,
3note tests). The gate builds it with the pinned compiler and runs it from the repository root; by hand:
4note OMC < tests/docs.om > build/docs && chmod +x build/docs && build/docs
5note Rules come from tests/docrules.txt, one per line; lines starting with # and blank lines are skipped.
6note file PATH PATH must exist and be readable; every forbid rule applies to it.
7note paths PATH as file, and every path-like word in PATH that contains a slash and ends .om, .md
8note or .txt must name a file of this repository: not absolute, no .. segment,
9note and present.
10note forbid TEXT TEXT (the rest of the line, case-sensitive) must not occur in any file.
11note need PATH TEXT PATH (declared by an earlier file or paths line) must contain TEXT.
12note cases PATH the gate's case file (ID EXIT ...; rob and # lines skipped). A sentence of a
13note checked file that says some exit codes have "no case" must not name a code
14note that a case of PATH expects, before or after those words.
15note Then every line ID|PATH|OLD|NEW of tests/docmutants.txt is a mutant: the line OLD of PATH (found
16note exactly once) replaced by NEW, or the whole file absent when OLD is *. Some rule must fail on it.
17note ID, PATH and OLD contain no "|"; NEW is the rest of the line and may.
18note Exit 0 with the last line "DOCS PASS ...", 1 with "DOCS FAIL failures=N", 3 with "DOCS NOT_RUN: ..."
19note when a rule or mutant line is malformed or a rule file cannot be read.
20note Bounds: 64 files, 64 forbid rules, 64 need rules, files below 4 MiB, rule and mutant files below
21note 64 KiB, paths below 4096 bytes. Each refuses with NOT_RUN or a FAIL line, never a trap.
22
23const FBN ulong 4194304
24const RLN ulong 65536
25const NOP ulong 4294967295
26
27global fb uchar 4194304
28global mb uchar 4194304
29global rl uchar 65536
30global mt uchar 65536
31global pa uchar 4096
32global pan ulong 1
33note file table: path rl[fpo .. fpo + fpl), fpr 1 when the path rule applies.
34global fpo ulong 64
35global fpl ulong 64
36global fpr ulong 64
37global nfl ulong 1
38note forbid rules: rl[zo .. zo + zl).
39global zo ulong 64
40global zl ulong 64
41global nz ulong 1
42note need rules: file nfi, text rl[nto .. nto + ntl).
43global nfi ulong 64
44global nto ulong 64
45global ntl ulong 64
46global nn ulong 1
47note cw[c] is 1 when a case of the cases file expects exit status c; ckon 1 once a cases line was read.
48global cw uchar 256
49global ckon ulong 1
50note cnt: 0 files checked, 1 paths files, 2 mutants, 3 mutants killed.
51global cnt ulong 4
52note quiet 1 while a mutant is checked (violations are counted, not printed).
53global quiet ulong 1
54note ml: start and end of the mutated line found by mlines, then the mutated file's length (mbuild).
55global ml ulong 3
56
57text tnl "\n"
58text trules "tests/docrules.txt"
59text tmuts "tests/docmutants.txt"
60text kfile "file "
61text kpaths "paths "
62text kforbid "forbid "
63text kneed "need "
64text kcases "cases "
65text knoc "no case"
66text tx1 ".om"
67text tx2 ".md"
68text tx3 ".txt"
69text tfail "DOCS FAIL "
70text tnr "DOCS NOT_RUN: "
71text tcolon ": "
72text tline "line "
73text tmiss "missing or unreadable file"
74text tbig "file of 4 MiB or more"
75text tforb "forbidden text: "
76text tneed "required text absent: "
77text tout "reference outside the repository: "
78text tgone "cited file missing: "
79text tclaim "says exit status "
80text tclaim2 " has no case, but the case file expects it"
81text tnorule "cannot read tests/docrules.txt"
82text tnomut "cannot read tests/docmutants.txt"
83text tnofile "no file rules"
84text tbadr "malformed rule line: "
85text tbadm "malformed mutant line: "
86text tkill "DOCS MUTANT killed "
87text tsurv "DOCS MUTANT SURVIVED "
88text tnf "DOCS MUTANT FAIL (old line not found exactly once, or the file is unreadable) "
89text tpass "DOCS PASS files="
90text tp1 " paths-files="
91text tp2 " forbid="
92text tp3 " need="
93text tp4 " cases-file="
94text tp5 " mutants-killed="
95text tslash "/"
96text tfails "DOCS FAIL failures="
97
98fn say t view uchar * to void
99r = write 1 t 0 len t
100end
101
102fn saynum v ulong to void
103b = new uchar 24 0
104x = v
105for i ulong 20
106put b sub 19 i uchar add rem x 10 48
107x = div x 10
108end
109k = ulong 0
110while lt k 19 bound 20
111if ne get b k 48
112break
113end
114k = add k 1
115end
116r = write 1 b k sub 20 k
117end
118
119fn sayrl s ulong n ulong to void
120r = write 1 rl s n
121end
122
123fn saymt s ulong n ulong to void
124r = write 1 mt s n
125end
126
127fn notrun t view uchar * to void
128say tnr
129say t
130say tnl
131exit 3
132end
133
134note ---- paths in pa ----
135fn pat t view uchar * to void
136for i ulong len t bound 4096
137put pa i get t i
138end
139put pan 0 len t
140end
141
142fn parl s ulong n ulong to void
143if ge n 4096
144notrun tbadr
145end
146for i ulong n bound 4096
147put pa i get rl add s i
148end
149put pan 0 n
150end
151
152fn pamt s ulong n ulong to void
153if ge n 4096
154notrun tbadm
155end
156for i ulong n bound 4096
157put pa i get mt add s i
158end
159put pan 0 n
160end
161
162note rd: file pa into buffer w (0 fb, 1 mb, 2 rl, 3 mt); the byte count, -1 when it cannot be opened
163note or read (a directory too), -2 when it fills the buffer.
164fn rd w ulong to long
165fd = fopen pa 0 get pan 0 0 0
166if lt fd 0
167ret long -1
168end
169cap = FBN
170if ge w 2
171cap = RLN
172end
173n = ulong 0
174res = long 0
175while true bound 100000
176r = long 0
177if eq w 0
178r = read int fd fb n sub cap n
179end
180if eq w 1
181r = read int fd mb n sub cap n
182end
183if eq w 2
184r = read int fd rl n sub cap n
185end
186if eq w 3
187r = read int fd mt n sub cap n
188end
189if lt r 0
190res = long -1
191break
192end
193if eq r 0
194res = long n
195break
196end
197n = add n ulong r
198if eq n cap
199res = long -2
200break
201end
202end
203c = fclose int fd
204ret res
205end
206
207note ---- lines and words ----
208fn rleol s ulong n ulong to ulong
209e = s
210while lt e n bound 65536
211if eq get rl e 10
212break
213end
214e = add e 1
215end
216ret e
217end
218
219fn mteol s ulong n ulong to ulong
220e = s
221while lt e n bound 65536
222if eq get mt e 10
223break
224end
225e = add e 1
226end
227ret e
228end
229
230fn mbeol s ulong n ulong to ulong
231e = s
232while lt e n bound 4194304
233if eq get mb e 10
234break
235end
236e = add e 1
237end
238ret e
239end
240
241fn fbeol s ulong n ulong to ulong
242e = s
243while lt e n bound 4194304
244if eq get fb e 10
245break
246end
247e = add e 1
248end
249ret e
250end
251
252fn fbskip i ulong b ulong to ulong
253j = i
254while lt j b bound 4194304
255if ne get fb j 32
256break
257end
258j = add j 1
259end
260ret j
261end
262
263fn fbword i ulong b ulong to ulong
264j = i
265while lt j b bound 4194304
266if eq get fb j 32
267break
268end
269j = add j 1
270end
271ret j
272end
273
274note rlkw: rl[s .. e) starts with t.
275fn rlkw s ulong e ulong t view uchar * to bool
276if lt sub e s len t
277ret false
278end
279for i ulong len t bound 64
280if ne get rl add s i get t i
281ret false
282end
283end
284ret true
285end
286
287note mtbar: the first | in mt[s .. e), or e.
288fn mtbar s ulong e ulong to ulong
289i = s
290while lt i e bound 65536
291if eq get mt i 124
292break
293end
294i = add i 1
295end
296ret i
297end
298
299note ffind: the index of path pa in the file table, or 99.
300fn ffind to ulong
301n = get pan 0
302for i ulong get nfl 0 bound 64
303if eq get fpl i n
304ok = true
305o = get fpo i
306for j ulong n bound 4096
307if ne get rl add o j get pa j
308ok = false
309break
310end
311end
312if ok
313ret i
314end
315end
316end
317ret 99
318end
319
320note ---- rules ----
321fn addf s ulong e ulong p ulong to bool
322k = get nfl 0
323if or ge s e ge k 64
324ret false
325end
326put fpo k s
327put fpl k sub e s
328put fpr k p
329put nfl 0 add k 1
330if eq p 1
331put cnt 1 add get cnt 1 1
332end
333ret true
334end
335
336fn addz s ulong e ulong to bool
337k = get nz 0
338if or ge s e ge k 64
339ret false
340end
341put zo k s
342put zl k sub e s
343put nz 0 add k 1
344ret true
345end
346
347fn addn s ulong e ulong to bool
348k = get nn 0
349if ge k 64
350ret false
351end
352sp = s
353while lt sp e bound 65536
354if eq get rl sp 32
355break
356end
357sp = add sp 1
358end
359if or eq sp s ge add sp 1 e
360ret false
361end
362parl s sub sp s
363fi = ffind
364if eq fi 99
365ret false
366end
367put nfi k fi
368put nto k add sp 1
369put ntl k sub e add sp 1
370put nn 0 add k 1
371ret true
372end
373
374note cline: one line fb[a .. b) of the cases file; marks the expected exit status of a case.
375fn cline a ulong b ulong to void
376i = fbskip a b
377if ge i b
378ret
379end
380if eq get fb i 35
381ret
382end
383j = fbword i b
384if eq sub j i 3
385if eq get fb i 114
386if eq get fb add i 1 111
387if eq get fb add i 2 98
388ret
389end
390end
391end
392end
393p = fbskip j b
394q = fbword p b
395if or eq p q gt sub q p 3
396ret
397end
398v = ulong 0
399for t ulong sub q p bound 3
400c = get fb add p t
401if or lt c 48 gt c 57
402ret
403end
404v = add mul v 10 ulong sub c 48
405end
406if lt v 256
407put cw v 1
408end
409end
410
411fn ldcases s ulong e ulong to bool
412if or ge s e eq get ckon 0 1
413ret false
414end
415parl s sub e s
416k = rd 0
417if lt k 0
418ret false
419end
420n = ulong k
421a = ulong 0
422while lt a n bound 4194304
423b = fbeol a n
424cline a b
425a = add b 1
426end
427put ckon 0 1
428ret true
429end
430
431fn rule1 s ulong e ulong to bool
432if eq s e
433ret true
434end
435if eq get rl s 35
436ret true
437end
438if rlkw s e kfile
439ret addf add s len kfile e 0
440end
441if rlkw s e kpaths
442ret addf add s len kpaths e 1
443end
444if rlkw s e kforbid
445ret addz add s len kforbid e
446end
447if rlkw s e kneed
448ret addn add s len kneed e
449end
450if rlkw s e kcases
451ret ldcases add s len kcases e
452end
453ret false
454end
455
456fn rules to void
457pat trules
458k = rd 2
459if lt k 0
460notrun tnorule
461end
462n = ulong k
463s = ulong 0
464while lt s n bound 65536
465e = rleol s n
466if not rule1 s e
467say tnr
468say tbadr
469sayrl s sub e s
470say tnl
471exit 3
472end
473s = add e 1
474end
475if eq get nfl 0 0
476notrun tnofile
477end
478end
479
480note ---- checks of fb[0 .. n) as file fi ----
481fn lineof p ulong to ulong
482l = ulong 1
483for i ulong p bound 4194304
484if eq get fb i 10
485l = add l 1
486end
487end
488ret l
489end
490
491note viol: the first part of a violation line (nothing while quiet): "DOCS FAIL PATH: line L: T".
492fn viol fi ulong p ulong t view uchar * to void
493if eq get quiet 0 1
494ret
495end
496say tfail
497sayrl get fpo fi get fpl fi
498say tcolon
499if ne p NOP
500say tline
501saynum lineof p
502say tcolon
503end
504say t
505end
506
507fn xrl s ulong n ulong to void
508if eq get quiet 0 0
509sayrl s n
510say tnl
511end
512end
513
514fn xfb s ulong n ulong to void
515if eq get quiet 0 0
516r = write 1 fb s n
517say tnl
518end
519end
520
521fn xnone to void
522if eq get quiet 0 0
523say tnl
524end
525end
526
527note fbat: fb[p .. p + n) equals rl[s .. s + n) (the caller keeps p + n within the file).
528fn fbat p ulong s ulong n ulong to bool
529for i ulong n bound 65536
530if ne get fb add p i get rl add s i
531ret false
532end
533end
534ret true
535end
536
537fn fbt p ulong t view uchar * to bool
538for i ulong len t bound 64
539if ne get fb add p i get t i
540ret false
541end
542end
543ret true
544end
545
546fn cforb fi ulong n ulong to ulong
547v = ulong 0
548for z ulong get nz 0 bound 64
549zs = get zo z
550zn = get zl z
551if gt zn n
552continue
553end
554for p ulong add sub n zn 1 bound 4194304
555if fbat p zs zn
556v = add v 1
557viol fi p tforb
558xrl zs zn
559end
560end
561end
562ret v
563end
564
565fn fbhas n ulong s ulong k ulong to bool
566if gt k n
567ret false
568end
569for p ulong add sub n k 1 bound 4194304
570if fbat p s k
571ret true
572end
573end
574ret false
575end
576
577fn cneed fi ulong n ulong to ulong
578v = ulong 0
579for k ulong get nn 0 bound 64
580if eq get nfi k fi
581if not fbhas n get nto k get ntl k
582v = add v 1
583viol fi NOP tneed
584xrl get nto k get ntl k
585end
586end
587end
588ret v
589end
590
591fn pch c uchar to bool
592if and ge c 97 le c 122
593ret true
594end
595if and ge c 65 le c 90
596ret true
597end
598if and ge c 48 le c 57
599ret true
600end
601if or eq c 95 or eq c 46 or eq c 47 eq c 45
602ret true
603end
604ret false
605end
606
607note endsw: fb[i .. j) is longer than t and ends with t.
608fn endsw i ulong j ulong t view uchar * to bool
609if le sub j i len t
610ret false
611end
612ret fbt sub j len t t
613end
614
615note dotseg: fb[i .. j) has a .. path segment.
616fn dotseg i ulong j ulong to bool
617k = i
618while lt k j bound 4194304
619if eq get fb k 46
620if lt add k 1 j
621if eq get fb add k 1 46
622pre = true
623if gt k i
624pre = eq get fb sub k 1 47
625end
626post = true
627e2 = add k 2
628if lt e2 j
629post = eq get fb e2 47
630end
631if and pre post
632ret true
633end
634end
635end
636end
637k = add k 1
638end
639ret false
640end
641
642note ctok: the path rule on the word fb[i .. j); 1 when it is violated.
643fn ctok fi ulong i ulong j0 ulong to ulong
644j = j0
645while gt j i bound 4194304
646if ne get fb sub j 1 46
647break
648end
649j = sub j 1
650end
651if eq j i
652ret 0
653end
654ok = endsw i j tx1
655if not ok
656ok = endsw i j tx2
657end
658if not ok
659ok = endsw i j tx3
660end
661if not ok
662ret 0
663end
664sl = false
665for k ulong sub j i bound 4194304
666if eq get fb add i k 47
667sl = true
668break
669end
670end
671if not sl
672ret 0
673end
674up = false
675if ge sub j i 3
676if eq get fb i 46
677if eq get fb add i 1 46
678if eq get fb add i 2 47
679up = true
680end
681end
682end
683end
684if or up dotseg i j
685viol fi i tout
686xfb i sub j i
687ret 1
688end
689if eq get fb i 47
690viol fi i tout
691xfb i sub j i
692ret 1
693end
694if ge sub j i 4096
695viol fi i tgone
696xfb i sub j i
697ret 1
698end
699for k ulong sub j i bound 4096
700put pa k get fb add i k
701end
702put pan 0 sub j i
703fd = fopen pa 0 get pan 0 0 0
704if lt fd 0
705viol fi i tgone
706xfb i sub j i
707ret 1
708end
709c = fclose int fd
710ret 0
711end
712
713fn cpath fi ulong n ulong to ulong
714if eq get fpr fi 0
715ret 0
716end
717v = ulong 0
718i = ulong 0
719while lt i n bound 4194304
720if not pch get fb i
721i = add i 1
722continue
723end
724j = i
725while lt j n bound 4194304
726if not pch get fb j
727break
728end
729j = add j 1
730end
731v = add v ctok fi i j
732i = j
733end
734ret v
735end
736
737fn isdig c uchar to bool
738ret and ge c 48 le c 57
739end
740
741fn isaln c uchar to bool
742if isdig c
743ret true
744end
745if and ge c 97 le c 122
746ret true
747end
748ret and ge c 65 le c 90
749end
750
751note cnums: digit runs in fb[a .. b) whose code a case expects; the reported line is rp.
752fn cnums fi ulong a ulong b ulong rp ulong to ulong
753v = ulong 0
754i = a
755while lt i b bound 4194304
756d = get fb i
757ok = isdig d
758if and ok gt i a
759if isaln get fb sub i 1
760ok = false
761end
762end
763if not ok
764i = add i 1
765continue
766end
767x = ulong 0
768while lt i b bound 4194304
769d = get fb i
770if not isdig d
771break
772end
773if lt x 1000
774x = add mul x 10 ulong sub d 48
775end
776i = add i 1
777end
778if lt x 256
779if eq get cw x 1
780v = add v 1
781viol fi rp tclaim
782if eq get quiet 0 0
783saynum x
784say tclaim2
785say tnl
786end
787end
788end
789end
790ret v
791end
792
793note csend: end of the sentence that contains "no case" at p, or n.
794fn csend p ulong n ulong to ulong
795e = add p len knoc
796if gt e n
797ret n
798end
799s = e
800while lt s n bound 4194304
801c = get fb s
802if eq c 10
803break
804end
805if eq c 46
806if lt add s 1 n
807if eq get fb add s 1 32
808break
809end
810end
811end
812s = add s 1
813end
814ret s
815end
816
817note csent: the sentence holding "no case" at p, from the line start or the last ". " to the next
818note ". " or the line end; every number in it whose code a case expects is a violation.
819fn csent fi ulong p ulong n ulong to ulong
820q = p
821while gt q 0 bound 4194304
822c = get fb sub q 1
823if eq c 10
824break
825end
826if and eq c 32 ge q 2
827if eq get fb sub q 2 46
828break
829end
830end
831q = sub q 1
832end
833v = cnums fi q p p
834s = csend p n
835v = add v cnums fi add p len knoc s p
836ret v
837end
838
839fn cnoc fi ulong n ulong to ulong
840if eq get ckon 0 0
841ret 0
842end
843kn = len knoc
844if lt n kn
845ret 0
846end
847v = ulong 0
848for p ulong add sub n kn 1 bound 4194304
849if fbt p knoc
850v = add v csent fi p n
851end
852end
853ret v
854end
855
856note fone: the violations of file fi whose bytes are fb[0 .. k) (k from rd: below 0, missing or too big).
857fn fone fi ulong k long to ulong
858if eq k -2
859viol fi NOP tbig
860xnone
861ret 1
862end
863if lt k 0
864viol fi NOP tmiss
865xnone
866ret 1
867end
868n = ulong k
869v = cforb fi n
870v = add v cneed fi n
871v = add v cpath fi n
872v = add v cnoc fi n
873ret v
874end
875
876fn clean to ulong
877bad = ulong 0
878for i ulong get nfl 0 bound 64
879parl get fpo i get fpl i
880k = rd 0
881bad = add bad fone i k
882put cnt 0 add get cnt 0 1
883end
884ret bad
885end
886
887note ---- mutants ----
888note mbeq: mb[s .. s + k) equals mt[os .. os + k).
889fn mbeq s ulong os ulong k ulong to bool
890for i ulong k bound 65536
891if ne get mb add s i get mt add os i
892ret false
893end
894end
895ret true
896end
897
898note mlines: the number of lines of mb[0 .. n) equal to mt[os .. oe); the last one's bounds go to ml.
899fn mlines n ulong os ulong oe ulong to ulong
900c = ulong 0
901s = ulong 0
902k = sub oe os
903while lt s n bound 4194304
904e = mbeol s n
905if eq sub e s k
906if mbeq s os k
907c = add c 1
908put ml 0 s
909put ml 1 e
910end
911end
912s = add e 1
913end
914ret c
915end
916
917note mbuild: fb = mb[0 .. n) with the line mb[ml0 .. ml1) replaced by mt[s0 .. s1); its length, or FBN.
918fn mbuild n ulong s0 ulong s1 ulong to ulong
919a = get ml 0
920b = get ml 1
921k = sub s1 s0
922t = add add a k sub n b
923if ge t FBN
924ret FBN
925end
926put ml 2 n
927mtail a b k
928for i ulong k bound 65536
929put fb add a i get mt add s0 i
930end
931ret t
932end
933
934note mtail: fb[0 .. a) = mb[0 .. a) and the bytes of mb from b on follow at a + k in fb.
935fn mtail a ulong b ulong k ulong to void
936for i ulong a bound 4194304
937put fb i get mb i
938end
939o = add a k
940m = sub get ml 2 b
941for i ulong m bound 4194304
942put fb add o i get mb add b i
943end
944end
945
946fn mreport ok bool s ulong b1 ulong to void
947if ok
948put cnt 3 add get cnt 3 1
949say tkill
950else
951say tsurv
952end
953saymt s sub b1 s
954say tnl
955end
956
957note mut1: the mutant mt[s .. e); 1 when it is not killed.
958fn mut1 s ulong e ulong to ulong
959b1 = mtbar s e
960b2 = mtbar add b1 1 e
961b3 = mtbar add b2 1 e
962if ge b3 e
963say tnr
964say tbadm
965saymt s sub e s
966say tnl
967exit 3
968end
969pamt add b1 1 sub b2 add b1 1
970fi = ffind
971if eq fi 99
972say tnr
973say tbadm
974saymt s sub e s
975say tnl
976exit 3
977end
978put cnt 2 add get cnt 2 1
979os = add b2 1
980if eq sub b3 os 1
981if eq get mt os 42
982v = fone fi long -1
983mreport gt v 0 s b1
984ret ite0 gt v 0
985end
986end
987k = rd 1
988n = ulong 0
989c = ulong 0
990if ge k 0
991n = ulong k
992c = mlines n os b3
993end
994if ne c 1
995say tnf
996saymt s sub b1 s
997say tnl
998ret 1
999end
1000t = mbuild n add b3 1 e
1001if eq t FBN
1002say tnf
1003saymt s sub b1 s
1004say tnl
1005ret 1
1006end
1007v = fone fi long t
1008mreport gt v 0 s b1
1009ret ite0 gt v 0
1010end
1011
1012note ite0: 0 when the mutant was killed, else 1.
1013fn ite0 killed bool to ulong
1014if killed
1015ret 0
1016end
1017ret 1
1018end
1019
1020fn muts to ulong
1021pat tmuts
1022k = rd 3
1023if lt k 0
1024notrun tnomut
1025end
1026n = ulong k
1027bad = ulong 0
1028s = ulong 0
1029while lt s n bound 65536
1030e = mteol s n
1031if gt e s
1032if ne get mt s 35
1033bad = add bad mut1 s e
1034end
1035end
1036s = add e 1
1037end
1038ret bad
1039end
1040
1041fn main to int
1042put quiet 0 0
1043rules
1044bad = clean
1045put quiet 0 1
1046bad = add bad muts
1047put quiet 0 0
1048if eq bad 0
1049say tpass
1050saynum get cnt 0
1051say tp1
1052saynum get cnt 1
1053say tp2
1054saynum get nz 0
1055say tp3
1056saynum get nn 0
1057say tp4
1058saynum get ckon 0
1059say tp5
1060saynum get cnt 3
1061say tslash
1062saynum get cnt 2
1063say tnl
1064ret 0
1065end
1066say tfails
1067saynum bad
1068say tnl
1069ret 1
1070end