ycl

Artifact [0739a36f8c]
Login

Artifact [0739a36f8c]

Artifact 0739a36f8cd9f214cfbe2e003bcb23414c66da6b:


#! /bin/env tclsh

package require {ycl test}

proc suite_main {} {
	namespace import [yclprefix]::chan::vso
	package require {ycl chan}
	namespace import [yclprefix]::chan
	rename chan yclchan
	namespace import [yclprefix]::chan::cmp
	namespace import [yclprefix]::chan::write
	package require {ycl chan prototype} 
	namespace import [yclprefix]::chan::prototype
	package require {ycl dir}
	namespace import [yclprefix]::dir
	package require {ycl file}
	namespace import [yclprefix]::file::puts
	rename puts fputs
	#package require {ycl iter}
	package require {ycl list}
	namespace import [yclprefix]::list::sl
	package require {ycl ns}
	namespace import [yclprefix]::ns::normalize
	package require {ycl string}
	namespace import [yclprefix]::string::dedent
	package require {ycl test data}
	namespace upvar [yclprefix]::test::data turingtest1 turingtest1
	package require {ycl vso}
	namespace import [yclprefix]::vso::universe
	[yclprefix]::test::init
	namespace import [yclprefix]::test::cleanup1

	namespace eval vso {}

	set setup1 {
		set tmpdir [dir mktempdir]
	}

	set setup2 {
		universe router vso::configure
		universe router vso::iter
		universe router vso::open 
		universe router vso::read 
		universe router vso::seek 
	}

	test chan {} -setup $setup1 -body {
		set chan [open $tmpdir/turing1 w]
		write $chan "123hello1\n"
		write $chan "hello2\n"
		write $chan "hello3\n"
		close $chan
		prototype .spawn chan1
		chan1 open $tmpdir/turing1
		lappend res [chan1 read 3]
		[yclprefix] iter for line in [chan1 iter] {
			lappend res $line
		}
		chan1 seek 0
		[yclprefix] iter for line in [chan1 iter] {
			lappend res $line
		}
		chan1 seek 0
		chan1 configure -eof h 
		[yclprefix] iter for line in [chan1 iter] {
			lappend res $line
		}

		#check for ability to read after [eof]
		chan1 configure -eof {}
		lappend res [chan1 read]

		rename chan1 {}
		#puts [myfile $ chan] 
		#rename myfile {}
		set res
	} -cleanup [cleanup1] -result [sl {
		123 hello1 hello2 hello3
		123hello1 hello2 hello3
		123
		"hello1\nhello2\nhello3\n"
	}]

	test chan_vso {} -setup $setup1\n$setup2 -body {
		set chan [open $tmpdir/turing1 w]
		write $chan "123hello1\n"
		write $chan "hello2\n"
		write $chan "hello3\n"
		close $chan
		set chan1 [[[yclprefix] chan vso .spawn chan1] init]
		vso::open $chan1 $tmpdir/turing1
		lappend res [vso::read $chan1 3]
		[yclprefix] iter for line in [vso::iter $chan1] {
			lappend res $line
		}
		vso::seek $chan1 0
		[yclprefix] iter for line in [vso::iter $chan1] {
			lappend res $line
		}
		vso::seek $chan1 0
		vso::configure $chan1 -eof h 
		[yclprefix] iter for line in [vso::iter $chan1] {
			lappend res $line
		}

		#check for ability to read after [eof]
		vso::configure $chan1 -eof {}
		lappend res [vso::read $chan1]

		rename chan1 {}
		#puts [myfile $ chan] 
		#rename myfile {}
		set res
	} -cleanup [cleanup1] -result [sl {
		123 hello1 hello2 hello3
		123hello1 hello2 hello3
		123
		"hello1\nhello2\nhello3\n"
	}]

	test cmp1 {} -setup $setup1 -body {
		fputs $tmpdir/file1 data {one} 
		fputs $tmpdir/file2 data {one} 
		set chan1 [open $tmpdir/file1]
		set chan2 [open $tmpdir/file2]
		cmp $chan1 $chan2
	} -cleanup [cleanup1] -result {-1}

	test cmp2 {} -setup $setup1 -body {
		fputs $tmpdir/file1 data {onep} 
		fputs $tmpdir/file2 data {one} 
		set chan1 [open $tmpdir/file1]
		set chan2 [open $tmpdir/file2]
		cmp $chan1 $chan2
	} -cleanup [cleanup1] -result {3}

	test cmp3 {} -setup $setup1 -body {
		fputs $tmpdir/file1 data {pone} 
		fputs $tmpdir/file2 data {one} 
		set chan1 [open $tmpdir/file1]
		set chan2 [open $tmpdir/file2]
		cmp $chan1 $chan2
	} -cleanup [cleanup1] -result {0}

	test cmp4 {} -setup $setup1 -body {
		fputs $tmpdir/file1 data {}
		fputs $tmpdir/file2 data {one} 
		set chan1 [open $tmpdir/file1]
		set chan2 [open $tmpdir/file2]
		cmp $chan1 $chan2
	} -cleanup [cleanup1] -result {0}

	test cmp5 {} -setup $setup1 -body {
		fputs $tmpdir/file1 data {one}
		fputs $tmpdir/file2 data {} 
		set chan1 [open $tmpdir/file1]
		set chan2 [open $tmpdir/file2]
		cmp $chan1 $chan2
	} -cleanup [cleanup1] -result {0}

	test cmp6 {} -setup $setup1 -body {
		fputs $tmpdir/file1 data {one two three}
		fputs $tmpdir/file2 data {one twp three}
		set chan1 [open $tmpdir/file1]
		set chan2 [open $tmpdir/file2]
		cmp $chan1 $chan2 2
	} -cleanup [cleanup1] -result {6}

	test iter {} -setup $setup1 -body {
		fputs $tmpdir/file1 data {one two three}
		set chan1 [open $tmpdir/file1]
		set iter [yclchan iter $chan1]
		while 1 {
			lappend res [$iter next]
		}
		return $res
	} -cleanup [cleanup1] -result [sl {
		o n e { } t w o { } t h r e e \n 
	}]

	test iter_lines {} -setup $setup1 -body {
		fputs $tmpdir/file1 data [dedent {
			one
			two three
		}]
		prototype .spawn chan1
		chan1 open $tmpdir/file1
		set iter [yclchan iter_lines [list [namespace which chan1]]]
		while 1 {
			lappend res [$iter]
		}
		return $res
	} -cleanup [cleanup1] -result [sl {
		{} one {two three} {}
	}]


	cleanupTests
}