From 8d83a9b6e88d38c1f1ea0cde00a37af1a5f1dfb0 Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Wed, 14 Dec 2022 05:30:29 -0800 Subject: [PATCH] initial commits --- t_regularfile.go | 18 ++++++++ t_textfile.go | 104 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 t_regularfile.go create mode 100644 t_textfile.go diff --git a/t_regularfile.go b/t_regularfile.go new file mode 100644 index 0000000..8a2e517 --- /dev/null +++ b/t_regularfile.go @@ -0,0 +1,18 @@ +package arbitrary + +import ( + "io/fs" +) + +func (arb T) RegularFile() fs.File { + + var fns [](func()fs.File) = [](func()fs.File){ + arb.TextFile, + arb.HTMLFile, + } + + fn := fns[arb.randomness.Intn(len(fns))] + + return fn() + +} diff --git a/t_textfile.go b/t_textfile.go new file mode 100644 index 0000000..4840720 --- /dev/null +++ b/t_textfile.go @@ -0,0 +1,104 @@ +package arbitrary + +import ( + "github.com/reiver/go-strfs" + + "io/fs" + "time" +) + +var ( + textFiles []string = []string{ + "", + + "Hello world!", + "Hello world!" +"\n", + "Hello world!" +"\r", + "Hello world!" +"\r\n", + "Hello world!" +"\u0085", + "Hello world!" +"\u2028", + "Hello world!" +"\u2029", + + "To Whom It May Concern:" +"\n"+"\n"+ "We were not alone." +"\n", + "To Whom It May Concern:" +"\r"+"\r"+ "We were not alone." +"\r", + "To Whom It May Concern:" +"\r\n"+"\r\n"+ "We were not alone." +"\r\n", + "To Whom It May Concern:" +"\u0085"+"\u0085"+ "We were not alone." +"\u0085", + "To Whom It May Concern:" +"\u2029"+ "We were not alone." +"\u2028", + } +) + +func (arb T) TextFile() fs.File { + + var filecontent strfs.Content + { + var s string = textFiles[arb.randomness.Intn(len(textFiles))] + + filecontent = strfs.CreateContent(s) + } + + var filename string + { + switch arb.randomness.Intn(10) { + case 0: + filename = ".plan" + case 1: + filename = ".project" + case 2: + filename = "message.txt" + case 3: + filename = "style.txt" + case 4: + filename = "style.txt" + case 5: + filename = "DOCUMENT.txt" + case 6: + filename = "file (2).txt" + default: + filename = arb.String() + if arb.Bool() { + filename += ".txt" + } + } + } + + var filemodtime time.Time = time.Now() + func(){ + if 0 == arb.randomness.Intn(10) { + filemodtime = time.Date(1970,1,1,0,0,0,0,time.UTC) + return + } + + if 0 == arb.randomness.Intn(10) { + filemodtime = time.Date(1924,6,7,20,6,3,11,time.UTC) + return + } + + if 0 == arb.randomness.Intn(10) { + filemodtime = time.Date(2022,12,14,20,12,23,17,time.UTC) + return + } + + if 0 == 3 { + year := arb.randomness.Intn(3000) + month := time.Month(1+arb.randomness.Intn(12)) + day := 1+arb.randomness.Intn(31) + hour := arb.randomness.Intn(24) + minute := arb.randomness.Intn(60) + second := arb.randomness.Intn(60) + nanosecond := arb.randomness.Intn(60) + + filemodtime = time.Date(year, month, day, hour, minute, second, nanosecond, time.UTC) + return + } + }() + + var regularfile strfs.RegularFile = strfs.RegularFile{ + FileContent: filecontent, + FileName: filename, + FileModTime: filemodtime, + } + + var file fs.File = ®ularfile + + return file +}