diff --git a/t_htmlfile.go b/t_htmlfile.go new file mode 100644 index 0000000..8a127b3 --- /dev/null +++ b/t_htmlfile.go @@ -0,0 +1,136 @@ +package arbitrary + +import ( + "github.com/reiver/go-strfs" + + "io/fs" + "time" +) + +var ( + htmlFiles []string = []string{ + "", + + "Hello world!", + "Hello world!" +"\n", + "Hello world!" +"\r", + "Hello world!" +"\r\n", + "Hello world!" +"\u0085", + "Hello world!" +"\u2028", + "Hello world!" +"\u2029", + + "", + "" +"\n", + "" +"\r", + "" +"\r\n", + "" +"\u0085", + "" +"\u2028", + "" +"\u2029", + + "
", + "" +"\n", + "" +"\r", + "" +"\r\n", + "" +"\u0085", + "" +"\u2028", + "" +"\u2029", + + "" +"\n" + "", + "" +"\r" + "", + "" +"\r\n" + "", + "" +"\u0085"+ "", + "" +"\u2028"+ "", + "" +"\u2029"+ "", + + "" +"\n" + "" +"\n", + "" +"\r" + "" +"\r", + "" +"\r\n" + "" +"\r\n", + "" +"\u0085"+ "" +"\u0085", + "" +"\u2028"+ "" +"\u2028", + "" +"\u2029"+ "" +"\u2029", + } +) + +func (arb T) HTMLFile() 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 = "index.html" + case 1: + filename = "index.htm" + case 2: + filename = "INDEX.HTML" + case 3: + filename = "INDEX.HTM" + case 4: + filename = "about.html" + case 5: + filename = "about.htm" + case 6: + filename = "something.HoTMeTaL" + default: + filename = arb.String() + if arb.Bool() { + filename += ".html" + } else if arb.Bool() { + filename += ".htm" + } else if arb.Bool() { + filename += ".HTML" + } else if arb.Bool() { + filename += ".HTM" + } else if arb.Bool() { + filename += ".HoTMeTaL" + } + } + } + + 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 +}