@ Test <EOL> fun copyToRestrictedReadSource ( )

{ <EOL> val root = createTempDirectory ( "<STR_LIT>" ) . cleanupRecursively ( ) <EOL> val srcFile = createTempFile ( root , "<STR_LIT>" ) <EOL> val dstFile = root . resolve ( "<STR_LIT>" ) <EOL> withRestrictedRead ( srcFile , alsoReset = listOf ( dstFile ) ) { <EOL> assertFailsWith < AccessDeniedException > { srcFile . copyTo ( dstFile ) } <EOL> } <EOL> val srcDirectory = createTempDirectory ( root , "<STR_LIT>" ) <EOL> val dstDirectory = root . resolve ( "<STR_LIT>" ) <EOL> withRestrictedRead ( srcDirectory , alsoReset = listOf ( dstDirectory ) ) { <EOL> srcDirectory . copyTo ( dstDirectory ) <EOL> assertFalse ( dstDirectory . isReadable ( ) ) <EOL> } <EOL> }


@ Test <EOL> fun copyToRestrictedWriteDestination ( )

{ <EOL> val root = createTempDirectory ( "<STR_LIT>" ) . cleanupRecursively ( ) <EOL> val srcFile = createTempFile ( root , "<STR_LIT>" ) <EOL> val dstFile = createTempFile ( root , "<STR_LIT>" ) <EOL> withRestrictedWrite ( dstFile ) { <EOL> assertFailsWith < FileAlreadyExistsException > { srcFile . copyTo ( dstFile ) } <EOL> try { <EOL> srcFile . copyTo ( dstFile , overwrite = true ) <EOL> assertTrue ( dstFile . isWritable ( ) ) <EOL> } catch ( _ : AccessDeniedException ) { <EOL> } <EOL> } <EOL> val srcDirectory = createTempDirectory ( root , "<STR_LIT>" ) <EOL> val dstDirectory = createTempDirectory ( root , "<STR_LIT>" ) <EOL> withRestrictedWrite ( dstDirectory ) { <EOL> assertFailsWith < FileAlreadyExistsException > { srcDirectory . copyTo ( dstDirectory ) } <EOL> srcDirectory . copyTo ( dstDirectory , overwrite = true ) <EOL> assertTrue ( dstDirectory . isWritable ( ) ) <EOL> } <EOL> }


@ Test <EOL> fun copyToSymlinkDestination ( )

{ <EOL> val root = createTempDirectory ( "<STR_LIT>" ) . cleanupRecursively ( ) <EOL> val targetFile = createTempFile ( root , "<STR_LIT>" ) . also { it . writeText ( "<STR_LIT>" ) } <EOL> val targetDirectory = createTempDirectory ( root , "<STR_LIT>" ) . also { it . resolve ( "<STR_LIT:a>" ) . createFile ( ) } <EOL> val srcFile = createTempFile ( root , "<STR_LIT>" ) . also { it . writeText ( "<STR_LIT>" ) } <EOL> val dstFile = root . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( targetFile ) ? : return <EOL> assertFailsWith < FileAlreadyExistsException > { <EOL> srcFile . copyTo ( dstFile ) <EOL> } <EOL> assertFailsWith < FileAlreadyExistsException > { <EOL> srcFile . copyTo ( dstFile , LinkOption . NOFOLLOW_LINKS ) <EOL> } <EOL> assertTrue ( dstFile . isSymbolicLink ( ) ) <EOL> assertEquals ( "<STR_LIT>" , dstFile . readText ( ) ) <EOL> val srcDirectory = createTempDirectory ( root , "<STR_LIT>" ) <EOL> val dstDirectory = root . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( targetDirectory ) ? : return <EOL> assertFailsWith < FileAlreadyExistsException > { <EOL> srcDirectory . copyTo ( dstDirectory ) <EOL> } <EOL> assertFailsWith < FileAlreadyExistsException > { <EOL> srcDirectory . copyTo ( dstDirectory , LinkOption . NOFOLLOW_LINKS ) <EOL> } <EOL> assertTrue ( dstDirectory . isSymbolicLink ( ) ) <EOL> assertEquals ( "<STR_LIT:a>" , dstDirectory . listDirectoryEntries ( ) . single ( ) . name ) <EOL> srcFile . copyTo ( dstFile , overwrite = true ) <EOL> assertFalse ( dstFile . isSymbolicLink ( ) ) <EOL> assertEquals ( "<STR_LIT>" , dstFile . readText ( ) ) <EOL> assertEquals ( "<STR_LIT>" , targetFile . readText ( ) ) <EOL> dstFile . deleteExisting ( ) <EOL> dstFile . tryCreateSymbolicLinkTo ( targetFile ) ! ! <EOL> srcFile . copyTo ( dstFile , StandardCopyOption . REPLACE_EXISTING , LinkOption . NOFOLLOW_LINKS ) <EOL> assertFalse ( dstFile . isSymbolicLink ( ) ) <EOL> assertEquals ( "<STR_LIT>" , dstFile . readText ( ) ) <EOL> assertEquals ( "<STR_LIT>" , targetFile . readText ( ) ) <EOL> srcDirectory . copyTo ( dstDirectory , overwrite = true ) <EOL> assertFalse ( dstDirectory . isSymbolicLink ( ) ) <EOL> assertEquals ( emptyList ( ) , dstDirectory . listDirectoryEntries ( ) ) <EOL> assertEquals ( "<STR_LIT:a>" , targetDirectory . listDirectoryEntries ( ) . single ( ) . name ) <EOL> dstDirectory . deleteExisting ( ) <EOL> dstDirectory . tryCreateSymbolicLinkTo ( targetDirectory ) ! ! <EOL> srcDirectory . copyTo ( dstDirectory , StandardCopyOption . REPLACE_EXISTING , LinkOption . NOFOLLOW_LINKS ) <EOL> assertFalse ( dstDirectory . isSymbolicLink ( ) ) <EOL> assertEquals ( emptyList ( ) , dstDirectory . listDirectoryEntries ( ) ) <EOL> assertEquals ( "<STR_LIT:a>" , targetDirectory . listDirectoryEntries ( ) . single ( ) . name ) <EOL> }


@ Test <EOL> fun copyToBrokenSymlinkDestination ( )

{ <EOL> val root = createTempDirectory ( "<STR_LIT>" ) . cleanupRecursively ( ) <EOL> val symlinkTarget = root . resolve ( "<STR_LIT>" ) <EOL> val srcFile = createTempFile ( root , "<STR_LIT>" ) . also { it . writeText ( "<STR_LIT>" ) } <EOL> val dstFile = root . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( symlinkTarget ) ? : return <EOL> assertFailsWith < FileAlreadyExistsException > { <EOL> srcFile . copyTo ( dstFile ) <EOL> } <EOL> assertFailsWith < FileAlreadyExistsException > { <EOL> srcFile . copyTo ( dstFile , LinkOption . NOFOLLOW_LINKS ) <EOL> } <EOL> assertTrue ( dstFile . isSymbolicLink ( ) ) <EOL> assertFailsWith < NoSuchFileException > { <EOL> dstFile . readText ( ) <EOL> } <EOL> val srcDirectory = createTempDirectory ( root , "<STR_LIT>" ) <EOL> val dstDirectory = root . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( symlinkTarget ) ? : return <EOL> assertFailsWith < FileAlreadyExistsException > { <EOL> srcDirectory . copyTo ( dstDirectory ) <EOL> } <EOL> assertFailsWith < FileAlreadyExistsException > { <EOL> srcDirectory . copyTo ( dstDirectory , LinkOption . NOFOLLOW_LINKS ) <EOL> } <EOL> assertTrue ( dstDirectory . isSymbolicLink ( ) ) <EOL> assertFailsWith < FileSystemException > { <EOL> dstDirectory . listDirectoryEntries ( ) <EOL> } <EOL> srcFile . copyTo ( dstFile , overwrite = true ) <EOL> assertFalse ( dstFile . isSymbolicLink ( ) ) <EOL> assertEquals ( "<STR_LIT>" , dstFile . readText ( ) ) <EOL> dstFile . deleteExisting ( ) <EOL> dstFile . tryCreateSymbolicLinkTo ( symlinkTarget ) ! ! <EOL> srcFile . copyTo ( dstFile , StandardCopyOption . REPLACE_EXISTING , LinkOption . NOFOLLOW_LINKS ) <EOL> assertFalse ( dstFile . isSymbolicLink ( ) ) <EOL> assertEquals ( "<STR_LIT>" , dstFile . readText ( ) ) <EOL> srcDirectory . copyTo ( dstDirectory , overwrite = true ) <EOL> assertFalse ( dstDirectory . isSymbolicLink ( ) ) <EOL> assertEquals ( emptyList ( ) , dstDirectory . listDirectoryEntries ( ) ) <EOL> dstDirectory . deleteExisting ( ) <EOL> dstDirectory . tryCreateSymbolicLinkTo ( symlinkTarget ) ! ! <EOL> srcDirectory . copyTo ( dstDirectory , StandardCopyOption . REPLACE_EXISTING , LinkOption . NOFOLLOW_LINKS ) <EOL> assertFalse ( dstDirectory . isSymbolicLink ( ) ) <EOL> assertEquals ( emptyList ( ) , dstDirectory . listDirectoryEntries ( ) ) <EOL> }


@ Test <EOL> fun copyToNameWithoutParent ( )

{ <EOL> val currentDir = Path ( "<STR_LIT>" ) . absolute ( ) <EOL> val srcFile = createTempFile ( ) . cleanup ( ) <EOL> val dstFile = createTempFile ( directory = currentDir ) . cleanup ( ) <EOL> srcFile . writeText ( "<STR_LIT>" , Charsets . UTF_8 ) <EOL> dstFile . deleteExisting ( ) <EOL> val dstRelative = Path ( dstFile . name ) <EOL> srcFile . copyTo ( dstRelative ) <EOL> assertEquals ( srcFile . readText ( ) , dstFile . readText ( ) ) <EOL> }


@ Test <EOL> fun copyToDstLinkPointingToSrc ( )

{ <EOL> for ( options in listOf ( arrayOf ( ) , arrayOf < CopyOption > ( LinkOption . NOFOLLOW_LINKS ) ) ) { <EOL> val root = createTempDirectory ( ) . cleanupRecursively ( ) <EOL> val src = root . resolve ( "<STR_LIT:src>" ) . createFile ( ) <EOL> val dstLink = root . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( src ) ? : return <EOL> assertTrue ( src . isSameFileAs ( dstLink ) ) <EOL> assertTrue ( dstLink . isSameFileAs ( src ) ) <EOL> assertFailsWith < FileAlreadyExistsException > { <EOL> src . copyTo ( dstLink , * options ) <EOL> } <EOL> assertTrue ( dstLink . isSymbolicLink ( ) ) <EOL> } <EOL> }


@ Test <EOL> fun copyToDstLinkPointingToSrcOverwrite ( )

{ <EOL> for ( options in listOf ( arrayOf ( ) , arrayOf < CopyOption > ( LinkOption . NOFOLLOW_LINKS ) ) ) { <EOL> val root = createTempDirectory ( ) . cleanupRecursively ( ) <EOL> val src = root . resolve ( "<STR_LIT:src>" ) . createFile ( ) <EOL> val dstLink = root . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( src ) ? : return <EOL> src . copyTo ( dstLink , StandardCopyOption . REPLACE_EXISTING , * options ) <EOL> assertFalse ( dstLink . isSymbolicLink ( ) ) <EOL> } <EOL> }


@ Test <EOL> fun copyToSrcLinkAndDstLinkPointingToSameFile ( )

{ <EOL> for ( options in listOf ( arrayOf ( ) , arrayOf < CopyOption > ( LinkOption . NOFOLLOW_LINKS ) ) ) { <EOL> val root = createTempDirectory ( ) . cleanupRecursively ( ) <EOL> val original = root . resolve ( "<STR_LIT>" ) . createFile ( ) <EOL> val srcLink = root . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( original ) ? : return <EOL> val dstLink = root . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( original ) ? : return <EOL> assertTrue ( srcLink . isSameFileAs ( dstLink ) ) <EOL> assertTrue ( dstLink . isSameFileAs ( srcLink ) ) <EOL> assertFailsWith < FileAlreadyExistsException > { <EOL> srcLink . copyTo ( dstLink , * options ) <EOL> } <EOL> assertTrue ( dstLink . isSymbolicLink ( ) ) <EOL> } <EOL> }


@ Test <EOL> fun copyToSrcLinkAndDstLinkPointingToSameFileOverwrite ( )

{ <EOL> for ( options in listOf ( arrayOf ( ) , arrayOf < CopyOption > ( LinkOption . NOFOLLOW_LINKS ) ) ) { <EOL> val root = createTempDirectory ( ) . cleanupRecursively ( ) <EOL> val original = root . resolve ( "<STR_LIT>" ) . createFile ( ) <EOL> val srcLink = root . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( original ) ? : return <EOL> val dstLink = root . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( original ) ? : return <EOL> srcLink . copyTo ( dstLink , StandardCopyOption . REPLACE_EXISTING , * options ) <EOL> if ( LinkOption . NOFOLLOW_LINKS in options ) { <EOL> assertTrue ( dstLink . isSymbolicLink ( ) ) <EOL> } else { <EOL> assertFalse ( dstLink . isSymbolicLink ( ) ) <EOL> } <EOL> } <EOL> }


@ Test <EOL> fun copyToSameLinkDifferentRoute ( )

{ <EOL> for ( options in listOf ( arrayOf ( ) , arrayOf < CopyOption > ( LinkOption . NOFOLLOW_LINKS ) ) ) { <EOL> val root = createTempDirectory ( ) . cleanupRecursively ( ) <EOL> val original = root . resolve ( "<STR_LIT>" ) . createFile ( ) <EOL> val srcLink = root . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( original ) ? : return <EOL> val dstLink = root . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( root ) ? . resolve ( "<STR_LIT>" ) ? : return <EOL> assertTrue ( srcLink . isSameFileAs ( dstLink ) ) <EOL> assertTrue ( dstLink . isSameFileAs ( srcLink ) ) <EOL> if ( LinkOption . NOFOLLOW_LINKS in options ) { <EOL> srcLink . copyTo ( dstLink , * options ) <EOL> } else { <EOL> assertFailsWith < FileAlreadyExistsException > { <EOL> srcLink . copyTo ( dstLink , * options ) <EOL> } <EOL> } <EOL> assertTrue ( dstLink . isSymbolicLink ( ) ) <EOL> } <EOL> }


@ Test <EOL> fun copyToSameLinkDifferentRouteOverwrite ( )

{ <EOL> for ( options in listOf ( arrayOf ( ) , arrayOf < CopyOption > ( LinkOption . NOFOLLOW_LINKS ) ) ) { <EOL> val root = createTempDirectory ( ) . cleanupRecursively ( ) <EOL> val original = root . resolve ( "<STR_LIT>" ) . createFile ( ) <EOL> val srcLink = root . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( original ) ? : return <EOL> val dstLink = root . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( root ) ? . resolve ( "<STR_LIT>" ) ? : return <EOL> if ( LinkOption . NOFOLLOW_LINKS in options ) { <EOL> srcLink . copyTo ( dstLink , StandardCopyOption . REPLACE_EXISTING , * options ) <EOL> } else { <EOL> val error = assertFailsWith < NoSuchFileException > { <EOL> srcLink . copyTo ( dstLink , StandardCopyOption . REPLACE_EXISTING , * options ) <EOL> } <EOL> assertEquals ( srcLink . toString ( ) , error . file ) <EOL> assertFalse ( srcLink . exists ( LinkOption . NOFOLLOW_LINKS ) ) <EOL> assertFalse ( dstLink . exists ( LinkOption . NOFOLLOW_LINKS ) ) <EOL> } <EOL> } <EOL> }


@ Test <EOL> fun copyToSameFileDifferentRoute ( )

{ <EOL> val root = createTempDirectory ( ) . cleanupRecursively ( ) <EOL> val src = root . resolve ( "<STR_LIT:src>" ) . createFile ( ) <EOL> val dst = root . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( root ) ? . resolve ( "<STR_LIT:src>" ) ? : return <EOL> assertTrue ( src . isSameFileAs ( dst ) ) <EOL> assertTrue ( dst . isSameFileAs ( src ) ) <EOL> src . copyTo ( dst ) <EOL> }


@ Test <EOL> fun copyToSameFileDifferentRouteOverwrite ( )

{ <EOL> val root = createTempDirectory ( ) . cleanupRecursively ( ) <EOL> val src = root . resolve ( "<STR_LIT:src>" ) . createFile ( ) <EOL> val dst = root . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( root ) ? . resolve ( "<STR_LIT:src>" ) ? : return <EOL> src . copyTo ( dst , overwrite = true ) <EOL> }


{ <EOL> val root = createTempDirectory ( "<STR_LIT>" ) . cleanupRecursively ( ) <EOL> val original = createTempFile ( root , "<STR_LIT>" ) <EOL> val srcFile = createTempFile ( root , "<STR_LIT:src>" ) <EOL> val dstFile = createTempFile ( root , "<STR_LIT>" ) <EOL> fun restoreSrcFile ( ) { original . copyTo ( srcFile , overwrite = true ) } <EOL> original . writeText ( "<STR_LIT>" ) <EOL> restoreSrcFile ( ) <EOL> assertFailsWith < FileAlreadyExistsException > ( "<STR_LIT>" ) { <EOL> srcFile . moveTo ( dstFile ) <EOL> } <EOL> var dst = srcFile . moveTo ( dstFile , overwrite = true ) <EOL> assertSame ( dst , dstFile ) <EOL> compareFiles ( original , dst , "<STR_LIT>" ) <EOL> assertTrue ( srcFile . notExists ( ) ) <EOL> restoreSrcFile ( ) <EOL> srcFile . moveTo ( srcFile ) <EOL> srcFile . moveTo ( srcFile , overwrite = true ) <EOL> compareFiles ( original , srcFile , "<STR_LIT>" ) <EOL> assertTrue ( dstFile . deleteIfExists ( ) ) <EOL> dst = srcFile . moveTo ( dstFile ) <EOL> compareFiles ( original , dst , "<STR_LIT>" ) <EOL> restoreSrcFile ( ) <EOL> val subDst = dstFile . resolve ( "<STR_LIT>" ) <EOL> assertFailsWith < FileSystemException > { srcFile . moveTo ( subDst ) } <EOL> assertFailsWith < FileSystemException > { srcFile . moveTo ( subDst , overwrite = true ) } <EOL> assertTrue ( dstFile . deleteIfExists ( ) ) <EOL> assertFailsWith < FileSystemException > { srcFile . moveTo ( subDst ) } <EOL> dstFile . createDirectory ( ) <EOL> val child = dstFile . resolve ( "<STR_LIT>" ) . createFile ( ) <EOL> assertFailsWith < DirectoryNotEmptyException > ( "<STR_LIT>" ) { <EOL> srcFile . moveTo ( dstFile , overwrite = true ) <EOL> } <EOL> child . deleteExisting ( ) <EOL> srcFile . moveTo ( dstFile , overwrite = true ) <EOL> compareFiles ( original , dstFile , "<STR_LIT>" ) <EOL> assertTrue ( srcFile . notExists ( ) ) <EOL> assertTrue ( dstFile . deleteIfExists ( ) ) <EOL> assertFailsWith < NoSuchFileException > { <EOL> srcFile . moveTo ( dstFile ) <EOL> } <EOL> srcFile . createDirectory ( ) <EOL> srcFile . resolve ( "<STR_LIT>" ) . writeText ( "<STR_LIT>" ) <EOL> dstFile . writeText ( "<STR_LIT>" ) <EOL> assertFailsWith < FileAlreadyExistsException > ( "<STR_LIT>" ) { <EOL> srcFile . moveTo ( dstFile ) <EOL> } <EOL> srcFile . moveTo ( dstFile , overwrite = true ) <EOL> assertTrue ( dstFile . isDirectory ( ) ) <EOL> assertEquals ( listOf ( dstFile / "<STR_LIT>" ) , dstFile . listDirectoryEntries ( ) , "<STR_LIT>" ) <EOL> }


private fun compareFiles ( src : Path , dst : Path , message : String ? = null )

{ <EOL> assertTrue ( dst . exists ( ) ) <EOL> assertEquals ( src . isRegularFile ( ) , dst . isRegularFile ( ) , message ) <EOL> assertEquals ( src . isDirectory ( ) , dst . isDirectory ( ) , message ) <EOL> if ( dst . isRegularFile ( ) ) { <EOL> assertTrue ( src . readBytes ( ) . contentEquals ( dst . readBytes ( ) ) , message ) <EOL> } <EOL> }


{ <EOL> val file = createTempFile ( ) . cleanup ( ) <EOL> assertEquals ( <NUM_LIT:0> , file . fileSize ( ) ) <EOL> file . writeBytes ( ByteArray ( <NUM_LIT:100> ) ) <EOL> assertEquals ( <NUM_LIT:100> , file . fileSize ( ) ) <EOL> file . appendText ( "<STR_LIT:Hello>" , Charsets . US_ASCII ) <EOL> assertEquals ( <NUM_LIT> , file . fileSize ( ) ) <EOL> file . deleteExisting ( ) <EOL> assertFailsWith < NoSuchFileException > { file . fileSize ( ) } <EOL> }


{ <EOL> val file = createTempFile ( ) . cleanup ( ) <EOL> file . deleteExisting ( ) <EOL> assertFailsWith < NoSuchFileException > { file . deleteExisting ( ) } <EOL> val dir = createTempDirectory ( ) . cleanup ( ) <EOL> dir . deleteExisting ( ) <EOL> assertFailsWith < NoSuchFileException > { dir . deleteExisting ( ) } <EOL> }


{ <EOL> val file = createTempFile ( ) . cleanup ( ) <EOL> assertTrue ( file . deleteIfExists ( ) ) <EOL> assertFalse ( file . deleteIfExists ( ) ) <EOL> val dir = createTempDirectory ( ) . cleanup ( ) <EOL> assertTrue ( dir . deleteIfExists ( ) ) <EOL> assertFalse ( dir . deleteIfExists ( ) ) <EOL> }


@ Test <EOL> fun attributeGettersOnFile ( )

{ <EOL> val file = createTempFile ( "<STR_LIT>" , "<STR_LIT>" ) . cleanup ( ) <EOL> assertTrue ( file . exists ( ) ) <EOL> assertFalse ( file . notExists ( ) ) <EOL> assertTrue ( file . isRegularFile ( ) ) <EOL> assertFalse ( file . isDirectory ( ) ) <EOL> assertFalse ( file . isSymbolicLink ( ) ) <EOL> assertTrue ( file . isReadable ( ) ) <EOL> assertTrue ( file . isWritable ( ) ) <EOL> assertTrue ( file . isSameFileAs ( file ) ) <EOL> file . isExecutable ( ) <EOL> file . isHidden ( ) <EOL> }


@ Test <EOL> fun attributeGettersOnDirectory ( )

{ <EOL> val file = createTempDirectory ( "<STR_LIT>" ) . cleanup ( ) <EOL> assertTrue ( file . exists ( ) ) <EOL> assertFalse ( file . notExists ( ) ) <EOL> assertFalse ( file . isRegularFile ( ) ) <EOL> assertTrue ( file . isDirectory ( ) ) <EOL> assertFalse ( file . isSymbolicLink ( ) ) <EOL> assertTrue ( file . isReadable ( ) ) <EOL> assertTrue ( file . isWritable ( ) ) <EOL> assertTrue ( file . isSameFileAs ( file ) ) <EOL> file . isExecutable ( ) <EOL> file . isHidden ( ) <EOL> }


@ Test <EOL> fun attributeGettersOnNonExistentPath ( )

{ <EOL> val file = createTempDirectory ( ) . cleanup ( ) . resolve ( "<STR_LIT:foo>" ) <EOL> assertFalse ( file . exists ( ) ) <EOL> assertTrue ( file . notExists ( ) ) <EOL> assertFalse ( file . isRegularFile ( ) ) <EOL> assertFalse ( file . isDirectory ( ) ) <EOL> assertFalse ( file . isSymbolicLink ( ) ) <EOL> assertFalse ( file . isReadable ( ) ) <EOL> assertFalse ( file . isWritable ( ) ) <EOL> assertTrue ( file . isSameFileAs ( file ) ) <EOL> file . isExecutable ( ) <EOL> try { <EOL> assertFalse ( file . isHidden ( ) ) <EOL> } catch ( e : IOException ) { <EOL> } <EOL> }


@ Test <EOL> fun readWriteAttributes ( )

{ <EOL> val file = createTempFile ( ) . cleanup ( ) <EOL> val modifiedTime = file . getLastModifiedTime ( ) <EOL> assertEquals ( modifiedTime , file . getAttribute ( "<STR_LIT>" ) ) <EOL> assertEquals ( modifiedTime , file . getAttribute ( "<STR_LIT>" ) ) <EOL> assertEquals ( modifiedTime , file . readAttributes < BasicFileAttributes > ( ) . lastModifiedTime ( ) ) <EOL> assertEquals ( modifiedTime , file . readAttributes ( "<STR_LIT>" ) [ "<STR_LIT>" ] ) <EOL> assertEquals ( modifiedTime , file . readAttributes ( "<STR_LIT:*>" ) [ "<STR_LIT>" ] ) <EOL> assertFailsWith < UnsupportedOperationException > { file . readAttributes < SpecialFileAttributes > ( ) } <EOL> assertFailsWith < UnsupportedOperationException > { file . readAttributes ( "<STR_LIT>" ) } <EOL> assertFailsWith < IllegalArgumentException > { file . readAttributes ( "<STR_LIT>" ) } <EOL> val newTime1 = FileTime . fromMillis ( modifiedTime . toMillis ( ) + <NUM_LIT> ) <EOL> file . setLastModifiedTime ( newTime1 ) <EOL> assertEquals ( newTime1 , file . getLastModifiedTime ( ) ) <EOL> val newTime2 = FileTime . fromMillis ( modifiedTime . toMillis ( ) + <NUM_LIT:2> * <NUM_LIT> ) <EOL> file . setAttribute ( "<STR_LIT>" , newTime2 ) <EOL> assertEquals ( newTime2 , file . getLastModifiedTime ( ) ) <EOL> val newTime3 = FileTime . fromMillis ( modifiedTime . toMillis ( ) + <NUM_LIT:3> * <NUM_LIT> ) <EOL> file . fileAttributesView < BasicFileAttributeView > ( ) . setTimes ( newTime3 , null , null ) <EOL> assertEquals ( newTime3 , file . getLastModifiedTime ( ) ) <EOL> assertFailsWith < UnsupportedOperationException > { file . fileAttributesView < SpecialFileAttributesView > ( ) } <EOL> assertNull ( file . fileAttributesViewOrNull < SpecialFileAttributesView > ( ) ) <EOL> file . setAttribute ( "<STR_LIT>" , null ) <EOL> assertEquals ( newTime3 , file . getLastModifiedTime ( ) ) <EOL> }


{ <EOL> val dir = createTempDirectory ( ) . cleanupRecursively ( ) <EOL> val original = createTempFile ( dir ) <EOL> original . writeBytes ( Random . nextBytes ( <NUM_LIT:100> ) ) <EOL> val link = try { <EOL> ( dir / ( "<STR_LIT>" + original . fileName ) ) . createLinkPointingTo ( original ) <EOL> } catch ( e : IOException ) { <EOL> println ( "<STR_LIT>" ) <EOL> return <EOL> } <EOL> assertTrue ( link . isRegularFile ( ) ) <EOL> assertTrue ( link . isRegularFile ( LinkOption . NOFOLLOW_LINKS ) ) <EOL> assertTrue ( original . isSameFileAs ( link ) ) <EOL> compareFiles ( original , link ) <EOL> assertFailsWith < NotLinkException > { link . readSymbolicLink ( ) } <EOL> }


{ <EOL> val dir = createTempDirectory ( ) . cleanupRecursively ( ) <EOL> val original = createTempFile ( dir ) <EOL> original . writeBytes ( Random . nextBytes ( <NUM_LIT:100> ) ) <EOL> val symlink = try { <EOL> ( dir / ( "<STR_LIT>" + original . fileName ) ) . createSymbolicLinkPointingTo ( original ) <EOL> } catch ( e : IOException ) { <EOL> println ( "<STR_LIT>" ) <EOL> return <EOL> } <EOL> assertTrue ( symlink . isRegularFile ( ) ) <EOL> assertFalse ( symlink . isRegularFile ( LinkOption . NOFOLLOW_LINKS ) ) <EOL> assertTrue ( original . isSameFileAs ( symlink ) ) <EOL> compareFiles ( original , symlink ) <EOL> assertEquals ( original , symlink . readSymbolicLink ( ) ) <EOL> }


@ Test <EOL> fun directoryEntriesList ( )

{ <EOL> val dir = createTempDirectory ( ) . cleanupRecursively ( ) <EOL> assertEquals ( <NUM_LIT:0> , dir . listDirectoryEntries ( ) . size ) <EOL> val file = dir . resolve ( "<STR_LIT>" ) . createFile ( ) <EOL> assertEquals ( listOf ( file ) , dir . listDirectoryEntries ( ) ) <EOL> val fileTxt = createTempFile ( dir , suffix = "<STR_LIT>" ) <EOL> assertEquals ( listOf ( fileTxt ) , dir . listDirectoryEntries ( "<STR_LIT>" ) ) <EOL> assertFailsWith < NotDirectoryException > { file . listDirectoryEntries ( ) } <EOL> }


@ Test <EOL> fun directoryEntriesUseSequence ( )

{ <EOL> val dir = createTempDirectory ( ) . cleanupRecursively ( ) <EOL> assertEquals ( <NUM_LIT:0> , dir . useDirectoryEntries { it . toList ( ) } . size ) <EOL> val file = dir . resolve ( "<STR_LIT>" ) . createFile ( ) <EOL> assertEquals ( listOf ( file ) , dir . useDirectoryEntries { it . toList ( ) } ) <EOL> val fileTxt = createTempFile ( dir , suffix = "<STR_LIT>" ) <EOL> assertEquals ( listOf ( fileTxt ) , dir . useDirectoryEntries ( "<STR_LIT>" ) { it . toList ( ) } ) <EOL> assertFailsWith < NotDirectoryException > { file . useDirectoryEntries { error ( "<STR_LIT>" ) } } <EOL> }


@ Test <EOL> fun directoryEntriesForEach ( )

{ <EOL> val dir = createTempDirectory ( ) . cleanupRecursively ( ) <EOL> dir . forEachDirectoryEntry { error ( "<STR_LIT>" ) } <EOL> val file = createTempFile ( dir ) <EOL> dir . forEachDirectoryEntry { assertEquals ( file , it ) } <EOL> val fileTxt = createTempFile ( dir , suffix = "<STR_LIT>" ) <EOL> dir . forEachDirectoryEntry ( "<STR_LIT>" ) { assertEquals ( fileTxt , it ) } <EOL> assertFailsWith < NotDirectoryException > { file . forEachDirectoryEntry { error ( "<STR_LIT>" ) } } <EOL> }


private fun testRelativeTo ( expected : String ? , path : String , base : String )

= <EOL> testRelativeTo ( expected ? . let { Path ( it ) } , Path ( path ) , Path ( base ) )


private fun testRelativeTo ( expected : String , path : Path , base : Path )

= <EOL> testRelativeTo ( Path ( expected ) , path , base )


private fun testRelativeTo ( expected : Path ? , path : Path , base : Path )

{ <EOL> val context = "<STR_LIT>" <EOL> if ( expected != null ) { <EOL> assertEquals ( expected , path . relativeTo ( base ) , context ) <EOL> } else { <EOL> val e = assertFailsWith < IllegalArgumentException > ( context ) { path . relativeTo ( base ) } <EOL> val message = assertNotNull ( e . message ) <EOL> assertTrue ( path . toString ( ) in message , message ) <EOL> assertTrue ( base . toString ( ) in message , message ) <EOL> } <EOL> assertEquals ( expected , path . relativeToOrNull ( base ) , context ) <EOL> assertEquals ( expected ? : path , path . relativeToOrSelf ( base ) , context ) <EOL> }


{ <EOL> val file1 = "<STR_LIT>" <EOL> val file2 = "<STR_LIT>" <EOL> testRelativeTo ( "<STR_LIT>" , file1 , file2 ) <EOL> val file3 = "<STR_LIT>" <EOL> testRelativeTo ( "<STR_LIT:baz>" , file1 , file3 ) <EOL> testRelativeTo ( "<STR_LIT>" , file3 , file1 ) <EOL> val file4 = "<STR_LIT>" <EOL> testRelativeTo ( "<STR_LIT:baz>" , file1 , file4 ) <EOL> testRelativeTo ( "<STR_LIT>" , file4 , file1 ) <EOL> testRelativeTo ( "<STR_LIT>" , file3 , file4 ) <EOL> testRelativeTo ( "<STR_LIT>" , file4 , file3 ) <EOL> val file5 = "<STR_LIT>" <EOL> testRelativeTo ( "<STR_LIT>" , file3 , file5 ) <EOL> testRelativeTo ( "<STR_LIT>" , file5 , file3 ) <EOL> testRelativeTo ( "<STR_LIT>" , file4 , file5 ) <EOL> testRelativeTo ( "<STR_LIT>" , file5 , file4 ) <EOL> if ( isBackslashSeparator ) { <EOL> val file6 = "<STR_LIT>" <EOL> val file7 = "<STR_LIT>" <EOL> testRelativeTo ( "<STR_LIT>" , file6 , file7 ) <EOL> testRelativeTo ( "<STR_LIT>" , file7 , file6 ) <EOL> val file8 = """<STR_LIT>""" <EOL> val file9 = """<STR_LIT>""" <EOL> testRelativeTo ( "<STR_LIT>" , file8 , file9 ) <EOL> testRelativeTo ( "<STR_LIT>" , file9 , file8 ) <EOL> } <EOL> if ( isCaseInsensitiveFileSystem ) { <EOL> testRelativeTo ( "<STR_LIT:bar>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> } <EOL> }


{ <EOL> val nested = Path ( "<STR_LIT>" ) <EOL> val base = Path ( "<STR_LIT:foo>" ) <EOL> testRelativeTo ( "<STR_LIT:bar>" , nested , base ) <EOL> testRelativeTo ( "<STR_LIT>" , base , nested ) <EOL> val empty = Path ( "<STR_LIT>" ) <EOL> val current = Path ( "<STR_LIT:.>" ) <EOL> val parent = Path ( "<STR_LIT>" ) <EOL> val outOfRoot = Path ( "<STR_LIT>" ) <EOL> testRelativeTo ( "<STR_LIT>" , outOfRoot , empty ) <EOL> testRelativeTo ( "<STR_LIT>" , outOfRoot , base ) <EOL> testRelativeTo ( "<STR_LIT:bar>" , outOfRoot , parent ) <EOL> testRelativeTo ( "<STR_LIT>" , parent , outOfRoot ) <EOL> val root = Path ( "<STR_LIT>" ) <EOL> val files = listOf ( nested , base , empty , outOfRoot , current , parent ) <EOL> val bases = listOf ( nested , base , empty , current ) <EOL> for ( file in files ) <EOL> testRelativeTo ( "<STR_LIT>" , file , file ) <EOL> for ( file in files ) { <EOL> @ Suppress ( "<STR_LIT>" ) <EOL> for ( base in bases ) { <EOL> val rootedFile = root . resolve ( file ) <EOL> val rootedBase = root . resolve ( base ) <EOL> assertEquals ( rootedFile . relativeTo ( rootedBase ) , file . relativeTo ( base ) , "<STR_LIT>" ) <EOL> } <EOL> } <EOL> }


{ <EOL> val absolute = Path ( "<STR_LIT>" ) <EOL> val relative = Path ( "<STR_LIT>" ) <EOL> val networkShare1 = Path ( """<STR_LIT>""" ) <EOL> val networkShare2 = Path ( """<STR_LIT>""" ) <EOL> val allFiles = listOf ( absolute , relative ) + if ( isBackslashSeparator ) listOf ( networkShare1 , networkShare2 ) else emptyList ( ) <EOL> for ( file in allFiles ) { <EOL> for ( base in allFiles ) { <EOL> if ( file != base ) testRelativeTo ( null , file , base ) <EOL> } <EOL> } <EOL> if ( isBackslashSeparator ) { <EOL> testRelativeTo ( null , "<STR_LIT>" , "<STR_LIT>" ) <EOL> } <EOL> testRelativeTo ( null , "<STR_LIT:foo>" , "<STR_LIT>" ) <EOL> testRelativeTo ( null , "<STR_LIT>" , "<STR_LIT>" ) <EOL> }


{ <EOL> testRelativeTo ( "<STR_LIT:kotlin>" , "<STR_LIT>" , "<STR_LIT:src>" ) <EOL> testRelativeTo ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> testRelativeTo ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> testRelativeTo ( "<STR_LIT>" , "<STR_LIT:test>" , "<STR_LIT>" ) <EOL> testRelativeTo ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> testRelativeTo ( null , "<STR_LIT>" , "<STR_LIT>" ) <EOL> }


{ <EOL> val relative = Path ( "<STR_LIT>" ) <EOL> assertTrue ( relative . absolute ( ) . isAbsolute ) <EOL> assertEquals ( relative . absolute ( ) . pathString , relative . absolutePathString ( ) ) <EOL> }


override fun isApplicable ( element : FirSimpleFunction , source : KtSourceElement ) : Boolean

= <EOL> source . kind !is KtFakeSourceElementKind


override fun checkPsi ( element : FirSimpleFunction , source : KtPsiSourceElement , psi : KtFunction , context : CheckerContext , reporter : DiagnosticReporter )

{ <EOL> val typeParamsNode = psi . typeParameterList <EOL> val nameNode = psi . nameIdentifier <EOL> if ( typeParamsNode != null && nameNode != null && typeParamsNode . startOffset > nameNode . startOffset ) { <EOL> reporter . reportOn ( source , FirErrors . DEPRECATED_TYPE_PARAMETER_SYNTAX , context ) <EOL> } <EOL> }


override fun checkLightTree ( element : FirSimpleFunction , source : KtLightSourceElement , context : CheckerContext , reporter : DiagnosticReporter )

{ <EOL> val typeParamsNode = source . treeStructure . typeParametersList ( source . lighterASTNode ) <EOL> val nameNode = source . treeStructure . nameIdentifier ( source . lighterASTNode ) <EOL> if ( typeParamsNode != null && nameNode != null && typeParamsNode . startOffset > nameNode . startOffset ) { <EOL> reporter . reportOn ( source , FirErrors . DEPRECATED_TYPE_PARAMETER_SYNTAX , context ) <EOL> } <EOL> }


internal fun PrettyPrinter . renderFe10Annotations ( annotations : Annotations , isSingleLineAnnotations : Boolean , renderAnnotationWithShortNames : Boolean , analysisContext : Fe10AnalysisContext , predicate : ( ClassId ) -> Boolean = { true } )

{ <EOL> val separator = if ( isSingleLineAnnotations ) "<STR_LIT:U+0020>" else "<STR_LIT:\n>" <EOL> for ( annotation in annotations ) { <EOL> val annotationClass = annotation . annotationClass ? : continue <EOL> val classId = annotationClass . classId <EOL> if ( classId != null && ! predicate ( classId ) ) { <EOL> continue <EOL> } <EOL> if ( annotationClass . fqNameSafe != StandardNames . FqNames . parameterName ) { <EOL> append ( '<CHAR_LIT>' ) <EOL> val rendered = if ( renderAnnotationWithShortNames ) annotation . fqName ? . shortName ( ) ? . render ( ) else annotation . fqName ? . render ( ) <EOL> append ( rendered ? : "<STR_LIT>" ) <EOL> val valueArguments = annotation . allValueArguments . entries . sortedBy { it . key . asString ( ) } <EOL> printCollectionIfNotEmpty ( valueArguments , separator = "<STR_LIT:U+002CU+0020>" , prefix = "<STR_LIT:(>" , postfix = "<STR_LIT:)>" ) { ( name , value ) -> <EOL> append ( name . render ( ) ) <EOL> append ( "<STR_LIT:U+0020=U+0020>" ) <EOL> append ( value . toKtAnnotationValue ( analysisContext ) . renderAsSourceCode ( ) ) <EOL> } <EOL> append ( separator ) <EOL> } <EOL> } <EOL> }


fun registerDeclarationNativeImplementation ( file : IrFile , declaration : IrDeclaration )

{ <EOL> if ( ! declaration . hasJsPolyfill ( ) ) return <EOL> val declarations = polyfillsPerFile [ file ] ? : hashSetOf ( ) <EOL> declarations . add ( declaration ) <EOL> polyfillsPerFile [ file ] = declarations <EOL> }


fun saveOnlyIntersectionOfNextDeclarationsFor ( file : IrFile , declarations : Set < IrDeclaration > )

{ <EOL> val polyfills = polyfillsPerFile [ file ] ? : return <EOL> polyfillsPerFile [ file ] = polyfills . intersect ( declarations ) . toHashSet ( ) <EOL> }


fun getAllPolyfillsFor ( file : IrFile ) : List < JsStatement >

= <EOL> polyfillsPerFile [ file ] . orEmpty ( ) . asImplementationList ( )


private fun Iterable < IrDeclaration > . asImplementationList ( )

= <EOL> asSequence ( ) . asImplementationList ( )


@ Suppress ( "<STR_LIT:UNCHECKED_CAST>" ) <EOL> private fun Sequence < IrDeclaration > . asImplementationList ( ) : List < JsStatement >

{ <EOL> return map { it to it . getAnnotation ( JsAnnotations . JsPolyfillFqn ) ! ! . getValueArgument ( <NUM_LIT:0> ) ! ! } <EOL> . distinctBy { ( it . second as IrConst < String > ) . value } <EOL> . flatMap { ( container , polyfill ) -> translateJsCodeIntoStatementList ( polyfill , null , container ) . orEmpty ( ) } <EOL> . toList ( ) <EOL> }


= ( object : II { } ) . ok ( )


= "<STR_LIT:OK>"


= foo ( )


= bar ( )


{ <EOL> println ( use ( getRandomEnumEntry ( ) ) ) <EOL> }


= value3


= X . B . value


public fun < T > yBegin ( column : ColumnReference < T > ) : PositionalMapping < T >

{ <EOL> return addPositionalMapping < T > ( Y_BEGIN , column . name ( ) , null ) <EOL> }

/**
 * Maps the `yBegin` aesthetic to a data column by [ColumnReference].
 *
 * @param column the data column to be mapped.
 * @return a [PositionalMapping] object representing the mapping.
 */


public fun < T > yBegin ( column : KProperty < T > ) : PositionalMapping < T >

{ <EOL> return addPositionalMapping < T > ( Y_BEGIN , column . name , null ) <EOL> }

/**
 * Maps the `yBegin` aesthetic to a data column by [KProperty].
 *
 * @param column the data column to be mapped.
 * @return a [PositionalMapping] object representing the mapping.
 */


public fun yBegin ( column : String ) : PositionalMapping < Any ? >

{ <EOL> return addPositionalMapping ( Y_BEGIN , column , null ) <EOL> }

/**
 * Maps the `yBegin` aesthetic to a data column by [String].
 *
 * @param column the data column to be mapped.
 * @return a [PositionalMapping] object representing the mapping.
 */


public fun < T > yBegin ( values : Iterable < T > ) : PositionalMapping < T >

{ <EOL> return addPositionalMapping < T > ( Y_BEGIN , values . toList ( ) , null , null ) <EOL> }

/**
 * Maps the `yBegin` aesthetic to iterable of values.
 *
 * @param values the iterable of values to be mapped.
 * @return a [PositionalMapping] object representing the mapping.
 */


public fun < T > yBegin ( values : DataColumn < T > ) : PositionalMapping < T >

{ <EOL> return addPositionalMapping < T > ( Y_BEGIN , values , null ) <EOL> }

/**
 * Maps the `yBegin` aesthetic to a data column.
 *
 * @param values the data column to be mapped.
 * @return a [PositionalMapping] object representing the mapping.
 */


{ <EOL> println ( <NUM_LIT> + <NUM_LIT:2> ) <EOL> }


{ <EOL> println ( <NUM_LIT> * <NUM_LIT:2> ) <EOL> }


{ <EOL> println ( <NUM_LIT> - <NUM_LIT:8> ) <EOL> }


{ <EOL> println ( <NUM_LIT> / <NUM_LIT:3> ) <EOL> }


private fun TypeValueModel . isLibReference ( ) : Boolean

{ <EOL> return fqName ? . isTsStdlibPrefixed ( ) == true <EOL> }


private fun HeritageModel . isLibReference ( ) : Boolean

{ <EOL> return value . isLibReference ( ) <EOL> }


private fun NameEntity . fqLib ( ) : NameEntity

{ <EOL> return TSLIBROOT . appendLeft ( this ) <EOL> }


private fun String . fqLib ( ) : NameEntity

{ <EOL> return IdentifierEntity ( this ) . fqLib ( ) <EOL> }


private fun TypeValueModel . createStdType ( name : String ) : TypeValueModel

{ <EOL> val nameEntity = IdentifierEntity ( name ) <EOL> return copy ( value = nameEntity , params = emptyList ( ) , fqName = nameEntity . fqLib ( ) ) <EOL> }


private fun TypeValueModel . resolveAsSubstitution ( ) : TypeValueModel ?

{ <EOL> val isLibReference = isLibReference ( ) <EOL> return if ( value == SubstitutedEntities . NON_NULLABLE . value || value == SubstitutedEntities . EXCLUDE . value || value == SubstitutedEntities . REQUIRED . value || value == SubstitutedEntities . OBJECT . value ) { <EOL> if ( isLibReference ) { <EOL> createStdType ( "<STR_LIT>" ) <EOL> } else null <EOL> } else if ( value == SubstitutedEntities . READONLY_ARRAY . value ) { <EOL> if ( isLibReference ) { <EOL> val fqName = "<STR_LIT>" . fqLib ( ) <EOL> copy ( value = fqName , fqName = fqName ) <EOL> } else null <EOL> } else if ( value == SubstitutedEntities . TEMPLATE_STRINGS_ARRAY . value ) { <EOL> val fqName = "<STR_LIT>" . fqLib ( ) <EOL> if ( isLibReference ) { <EOL> val stringFqName = "<STR_LIT:String>" . fqLib ( ) <EOL> copy ( value = fqName , fqName = fqName , params = listOf ( TypeParameterModel ( TypeValueModel ( value = stringFqName , fqName = stringFqName , params = emptyList ( ) , metaDescription = null , nullable = false ) , emptyList ( ) ) ) ) <EOL> } else null <EOL> } else null <EOL> }


@ Suppress ( "<STR_LIT:UNCHECKED_CAST>" ) <EOL> private fun ClassLikeModel . convertToTypeAlias ( forbiddenParent : HeritageModel ) : TypeAliasModel

{ <EOL> return TypeAliasModel ( name = name , typeParameters = typeParameters . map { it . copy ( constraints = emptyList ( ) ) } , visibilityModifier = VisibilityModifierModel . DEFAULT , comment = null , typeReference = forbiddenParent . value . copy ( params = forbiddenParent . typeParams . map { <EOL> TypeParameterModel ( it , emptyList ( ) ) <EOL> } ) ) <EOL> }


override fun lowerFunctionModel ( ownerContext : NodeOwner < FunctionModel > , parentModule : ModuleModel ) : FunctionModel

{ <EOL> val declaration = ownerContext . node <EOL> val declarationResolved = declaration . extend ? . let { extendedInterface -> <EOL> var commentResolved = declaration . comment <EOL> val extendResolved = substituteInlines . get ( extendedInterface . name ) ? . let { substitutedName -> <EOL> val comment = declaration . comment <EOL> commentResolved = when ( comment ) { <EOL> is SimpleCommentEntity -> SimpleCommentEntity ( "<STR_LIT>" ) <EOL> else -> comment <EOL> } <EOL> extendedInterface . copy ( name = IdentifierEntity ( substitutedName ) ) <EOL> } ? : extendedInterface <EOL> declaration . copy ( extend = extendResolved , comment = commentResolved ) <EOL> } ? : declaration <EOL> return super . lowerFunctionModel ( ownerContext . copy ( node = declarationResolved ) , parentModule ) <EOL> }


override fun lowerTopLevelModel ( ownerContext : NodeOwner < TopLevelModel > , parentModule : ModuleModel ) : TopLevelModel ?

{ <EOL> val declaration = ownerContext . node <EOL> val declarationResolved = if ( declaration is ClassLikeModel ) { <EOL> declaration . parentEntities . firstOrNull { parentEntity -> <EOL> parentEntity . isLibReference ( ) && stdLibFinalEntities . contains ( parentEntity . value . value ) <EOL> } ? . let { forbiddenParent -> <EOL> declaration . convertToTypeAlias ( forbiddenParent ) <EOL> } <EOL> } else { <EOL> null <EOL> } ? : declaration <EOL> return super . lowerTopLevelModel ( ownerContext . copy ( node = declarationResolved ) , parentModule ) <EOL> }


override fun lowerTypeValueModel ( ownerContext : NodeOwner < TypeValueModel > ) : TypeValueModel

{ <EOL> val declaration = ownerContext . node <EOL> return declaration . resolveAsSubstitution ( ) ? . let { resolved -> <EOL> super . lowerTypeValueModel ( ownerContext . copy ( node = resolved ) ) <EOL> } ? : super . lowerTypeValueModel ( ownerContext ) <EOL> }


override fun lower ( module : ModuleModel ) : ModuleModel

{ <EOL> return SubstituteLowering ( ) . lowerRoot ( module , NodeOwner ( module , null ) ) <EOL> }


{ <EOL> node . data . get ( MyEnum . EnumEntry ) <EOL> val map = node . data <EOL> map . get ( MyEnum . EnumEntry ) <EOL> }


private fun test ( node : FooEnumMap < * > )


{ <EOL> node . data . get ( C ) <EOL> }


{ <EOL> val x : A ? = A ( ) <EOL> val y : A ? <EOL> if ( u == <NUM_LIT:0> ) { <EOL> y = x <EOL> } <EOL> else { <EOL> y = null <EOL> } <EOL> y ! ! <EOL> }


suspend fun < S > GenericController < S > . yieldAll ( s : Collection < S > ) : String

= "<STR_LIT>"


suspend fun < S > GenericController < S > . yieldAll ( s : Set < S > ) : Int

= <NUM_LIT:4>


fun < T , R > generate ( g : suspend GenericController < T > . ( ) -> R ) : Pair < T , R >

= TODO ( )


fun < X > setOf ( vararg x : X ) : Set < X >

= TODO ( )


fun < X > listOf ( vararg x : X ) : List < X >

= TODO ( )


override fun loadProcessors ( ) : LoadedProcessors

{ <EOL> this . processorLoader = EfficientProcessorLoader ( options , logger ) <EOL> return processorLoader ! ! . loadProcessors ( ) <EOL> }


override fun analysisCompleted ( project : Project , module : ModuleDescriptor , bindingTrace : BindingTrace , files : Collection < KtFile > ) : AnalysisResult ?

{ <EOL> try { <EOL> return super . analysisCompleted ( project , module , bindingTrace , files ) <EOL> } finally { <EOL> processorLoader ? . close ( ) <EOL> clearJavacZipCaches ( ) <EOL> } <EOL> }


{ <EOL> try { <EOL> val zipFileIndexCacheClass = Class . forName ( "<STR_LIT>" ) <EOL> val zipFileIndexCacheInstance = zipFileIndexCacheClass . getMethod ( "<STR_LIT>" ) . invoke ( null ) <EOL> zipFileIndexCacheClass . getMethod ( "<STR_LIT>" ) . invoke ( zipFileIndexCacheInstance ) <EOL> } catch ( e : Throwable ) { <EOL> } <EOL> }


private fun setAnnotationProcessingComplete ( ) : Boolean

{ <EOL> if ( annotationProcessingComplete ) return true <EOL> annotationProcessingComplete = true <EOL> return false <EOL> }


override fun doAnalysis ( project : Project , module : ModuleDescriptor , projectContext : ProjectContext , files : Collection < KtFile > , bindingTrace : BindingTrace , componentProvider : ComponentProvider ) : AnalysisResult ?

{ <EOL> if ( options . mode == APT_ONLY ) { <EOL> return AnalysisResult . EMPTY <EOL> } <EOL> return super . doAnalysis ( project , module , projectContext , files , bindingTrace , componentProvider ) <EOL> }


{ <EOL> if ( setAnnotationProcessingComplete ( ) ) return null <EOL> fun doNotGenerateCode ( ) = AnalysisResult . success ( BindingContext . EMPTY , module , shouldGenerateCode = false ) <EOL> logger . info { "<STR_LIT>" } <EOL> val bindingContext = bindingTrace . bindingContext <EOL> if ( options . mode . generateStubs ) { <EOL> logger . info { "<STR_LIT>" + files . map { it . virtualFile ? . name ? : "<STR_LIT>" } } <EOL> contextForStubGeneration ( project , module , bindingContext , files . toList ( ) ) . use { context -> <EOL> generateKotlinSourceStubs ( context ) <EOL> } <EOL> } <EOL> if ( ! options . mode . runAnnotationProcessing ) return doNotGenerateCode ( ) <EOL> val processors = loadProcessors ( ) <EOL> if ( processors . processors . isEmpty ( ) ) return if ( options . mode != WITH_COMPILATION ) doNotGenerateCode ( ) else null <EOL> val kaptContext = KaptContext ( options , false , logger ) <EOL> fun handleKaptError ( error : KaptError ) : AnalysisResult { <EOL> val cause = error . cause <EOL> if ( cause != null ) { <EOL> kaptContext . logger . exception ( cause ) <EOL> } <EOL> return AnalysisResult . compilationError ( bindingTrace . bindingContext ) <EOL> } <EOL> try { <EOL> runAnnotationProcessing ( kaptContext , processors ) <EOL> } catch ( error : KaptBaseError ) { <EOL> val kind = when ( error . kind ) { <EOL> KaptBaseError . Kind . EXCEPTION -> KaptError . Kind . EXCEPTION <EOL> KaptBaseError . Kind . ERROR_RAISED -> KaptError . Kind . ERROR_RAISED <EOL> } <EOL> val cause = error . cause <EOL> return handleKaptError ( if ( cause != null ) KaptError ( kind , cause ) else KaptError ( kind ) ) <EOL> } catch ( error : KaptError ) { <EOL> return handleKaptError ( error ) <EOL> } catch ( thr : Throwable ) { <EOL> return AnalysisResult . internalError ( bindingTrace . bindingContext , thr ) <EOL> } finally { <EOL> kaptContext . close ( ) <EOL> } <EOL> return if ( options . mode != WITH_COMPILATION ) { <EOL> doNotGenerateCode ( ) <EOL> } else { <EOL> AnalysisResult . RetryWithAdditionalRoots ( bindingTrace . bindingContext , module , listOf ( options . sourcesOutputDir ) , listOfNotNull ( options . sourcesOutputDir , options . getKotlinGeneratedSourcesDirectory ( ) ) , addToEnvironment = true ) <EOL> } <EOL> }


private fun runAnnotationProcessing ( kaptContext : KaptContext , processors : LoadedProcessors )

{ <EOL> if ( ! options . mode . runAnnotationProcessing ) return <EOL> val javaSourceFiles = options . collectJavaSourceFiles ( kaptContext . sourcesToReprocess ) <EOL> logger . info { "<STR_LIT>" + javaSourceFiles . joinToString { it . normalize ( ) . absolutePath } } <EOL> val ( annotationProcessingTime ) = measureTimeMillis { <EOL> kaptContext . doAnnotationProcessing ( javaSourceFiles , processors . processors ) <EOL> } <EOL> logger . info { "<STR_LIT>" } <EOL> if ( options . detectMemoryLeaks != DetectMemoryLeaksMode . NONE ) { <EOL> MemoryLeakDetector . add ( processors . classLoader ) <EOL> val isParanoid = options . detectMemoryLeaks == DetectMemoryLeaksMode . PARANOID <EOL> val ( leakDetectionTime , leaks ) = measureTimeMillis { MemoryLeakDetector . process ( isParanoid ) } <EOL> logger . info { "<STR_LIT>" } <EOL> for ( leak in leaks ) { <EOL> logger . warn ( buildString { <EOL> appendLine ( "<STR_LIT>" ) <EOL> appendLine ( "<STR_LIT>" ) <EOL> append ( leak . description ) <EOL> } ) <EOL> } <EOL> } <EOL> }


private fun contextForStubGeneration ( project : Project , module : ModuleDescriptor , bindingContext : BindingContext , files : List < KtFile > ) : KaptContextForStubGeneration

{ <EOL> val builderFactory = OriginCollectingClassBuilderFactory ( ClassBuilderMode . KAPT3 ) <EOL> val configuration = compilerConfiguration . copy ( ) . apply { <EOL> put ( JVMConfigurationKeys . DO_NOT_CLEAR_BINDING_CONTEXT , true ) <EOL> } <EOL> val targetId = TargetId ( name = configuration [ CommonConfigurationKeys . MODULE_NAME ] ? : module . name . asString ( ) , type = "<STR_LIT>" ) <EOL> val generationState = GenerationState . Builder ( project , builderFactory , module , bindingContext , configuration ) <EOL> . targetId ( targetId ) <EOL> . build ( ) <EOL> val ( classFilesCompilationTime ) = measureTimeMillis { <EOL> KotlinCodegenFacade . compileCorrectFiles ( files , generationState , JvmIrCodegenFactory ( configuration , configuration [ CLIConfigurationKeys . PHASE_CONFIG ] ) ) <EOL> } <EOL> val compiledClasses = builderFactory . compiledClasses <EOL> val origins = builderFactory . origins <EOL> logger . info { "<STR_LIT>" } <EOL> logger . info { "<STR_LIT>" + compiledClasses . joinToString { it . name } } <EOL> return KaptContextForStubGeneration ( options , false , logger , compiledClasses , origins , generationState ) <EOL> }


private fun generateKotlinSourceStubs ( kaptContext : KaptContextForStubGeneration )

{ <EOL> val converter = ClassFileToSourceStubConverter ( kaptContext , generateNonExistentClass = true ) <EOL> val ( stubGenerationTime , kaptStubs ) = measureTimeMillis { <EOL> converter . convert ( ) <EOL> } <EOL> logger . info { "<STR_LIT>" } <EOL> logger . info { "<STR_LIT>" + kaptStubs . joinToString { it . file . sourcefile . name } } <EOL> saveStubs ( kaptContext , kaptStubs , logger . messageCollector ) <EOL> saveIncrementalData ( kaptContext , logger . messageCollector , converter ) <EOL> }


protected open fun saveStubs ( kaptContext : KaptContextForStubGeneration , stubs : List < KaptStub > , messageCollector : MessageCollector , )

{ <EOL> val reportOutputFiles = kaptContext . generationState . configuration . getBoolean ( CommonConfigurationKeys . REPORT_OUTPUT_FILES ) <EOL> val outputFiles = if ( reportOutputFiles ) kaptContext . generationState . factory . asList ( ) . associateBy { <EOL> it . relativePath . substringBeforeLast ( "<STR_LIT>" , missingDelimiterValue = "<STR_LIT>" ) <EOL> } else null <EOL> for ( kaptStub in stubs ) { <EOL> val stub = kaptStub . file <EOL> val className = ( stub . defs . first { it is JCTree . JCClassDecl } as JCTree . JCClassDecl ) . simpleName . toString ( ) <EOL> val packageName = stub . getPackageNameJava9Aware ( ) ? . toString ( ) ? : "<STR_LIT>" <EOL> val packageDir = <EOL> if ( packageName . isEmpty ( ) ) options . stubsOutputDir else File ( options . stubsOutputDir , packageName . replace ( '<CHAR_LIT:.>' , '<CHAR_LIT:/>' ) ) <EOL> packageDir . mkdirs ( ) <EOL> val sourceFile = File ( packageDir , "<STR_LIT>" ) <EOL> val classFilePathWithoutExtension = if ( packageName . isEmpty ( ) ) { <EOL> className <EOL> } else { <EOL> "<STR_LIT>" <EOL> } <EOL> fun reportStubsOutputForIC ( generatedFile : File ) { <EOL> if ( ! reportOutputFiles ) return <EOL> if ( classFilePathWithoutExtension == "<STR_LIT>" ) return <EOL> val sourceFiles = ( outputFiles ? . get ( classFilePathWithoutExtension ) ? : error ( "<STR_LIT>" ) ) . sourceFiles <EOL> messageCollector . report ( OUTPUT , OutputMessageUtil . formatOutputMessage ( sourceFiles , generatedFile ) ) <EOL> } <EOL> reportStubsOutputForIC ( sourceFile ) <EOL> sourceFile . writeText ( stub . prettyPrint ( kaptContext . context ) ) <EOL> kaptStub . writeMetadataIfNeeded ( forSource = sourceFile , :: reportStubsOutputForIC ) <EOL> } <EOL> }


protected open fun saveIncrementalData ( kaptContext : KaptContextForStubGeneration , messageCollector : MessageCollector , converter : ClassFileToSourceStubConverter )

{ <EOL> val incrementalDataOutputDir = options . incrementalDataOutputDir ? : return <EOL> val reportOutputFiles = kaptContext . generationState . configuration . getBoolean ( CommonConfigurationKeys . REPORT_OUTPUT_FILES ) <EOL> kaptContext . generationState . factory . writeAll ( incrementalDataOutputDir , if ( ! reportOutputFiles ) null else fun ( sources : List < File > , output : File ) { <EOL> messageCollector . report ( OUTPUT , OutputMessageUtil . formatOutputMessage ( sources , output ) ) <EOL> } ) <EOL> }


protected abstract fun loadProcessors ( ) : LoadedProcessors


inline fun < T > measureTimeMillis ( block : ( ) -> T ) : Pair < Long , T >

{ <EOL> val start = System . currentTimeMillis ( ) <EOL> val result = block ( ) <EOL> return Pair ( System . currentTimeMillis ( ) - start , result ) <EOL> }


= a + b * <NUM_LIT:2>


{ <EOL> val array = Array ( <NUM_LIT:10> ) { <NUM_LIT:100> } <EOL> val array1 = Array ( <NUM_LIT:3> ) { <NUM_LIT:0> } <EOL> var length = array . size - <NUM_LIT:1> <EOL> var sum = <NUM_LIT:0> <EOL> array . forEach { <EOL> sum += it <EOL> } <EOL> for ( i in array . indices ) { <EOL> array [ i ] = <NUM_LIT:6> <EOL> } <EOL> for ( i in <NUM_LIT:0> until array . size ) { <EOL> array [ i ] = <NUM_LIT:7> <EOL> } <EOL> for ( i in array . size - <NUM_LIT:1> downTo <NUM_LIT:1> ) { <EOL> array [ i ] = <NUM_LIT:7> <EOL> } <EOL> for ( it in array ) { <EOL> sum += it <EOL> } <EOL> for ( i in <NUM_LIT:0> .. array . size - <NUM_LIT:1> step <NUM_LIT:2> ) { <EOL> array [ i ] = <NUM_LIT:7> <EOL> } <EOL> for ( i in <NUM_LIT:0> until array . size step <NUM_LIT:2> ) { <EOL> array [ i ] = <NUM_LIT:7> <EOL> } <EOL> for ( i in array . indices step <NUM_LIT:2> ) { <EOL> array [ i ] = <NUM_LIT:6> <EOL> } <EOL> for ( i in array . size - <NUM_LIT:1> downTo <NUM_LIT:1> step <NUM_LIT:2> ) { <EOL> array [ i ] = <NUM_LIT:7> <EOL> } <EOL> for ( ( index , value ) in array . withIndex ( ) ) { <EOL> array [ index ] = <NUM_LIT:8> <EOL> } <EOL> for ( ( i , v ) in ( <NUM_LIT:0> .. array . size - <NUM_LIT:1> step <NUM_LIT:2> ) . withIndex ( ) ) { <EOL> array [ v ] = <NUM_LIT:8> <EOL> array [ i ] = <NUM_LIT:6> <EOL> } <EOL> for ( i in array . reversed ( ) ) { <EOL> sum += i <EOL> } <EOL> for ( i in ( <NUM_LIT:0> .. array . size - <NUM_LIT:1> ) . reversed ( ) ) { <EOL> array [ i ] = <NUM_LIT:10> <EOL> } <EOL> for ( i in <NUM_LIT:0> until array . size ) { <EOL> array [ i ] = <NUM_LIT:7> <EOL> for ( j in <NUM_LIT:0> until array1 . size ) { <EOL> array1 [ j ] = array [ i ] <EOL> } <EOL> } <EOL> val size = array . size - <NUM_LIT:1> <EOL> val size1 = size <EOL> for ( i in <NUM_LIT:0> .. size1 ) { <EOL> foo ( array [ i ] , array [ i ] ) <EOL> } <EOL> for ( i in <NUM_LIT:0> .. array . size - <NUM_LIT:2> ) { <EOL> array [ i + <NUM_LIT:1> ] = array [ i ] <EOL> } <EOL> if ( array . toList ( ) != listOf ( <NUM_LIT:7> , <NUM_LIT:7> , <NUM_LIT:7> , <NUM_LIT:7> , <NUM_LIT:7> , <NUM_LIT:7> , <NUM_LIT:7> , <NUM_LIT:7> , <NUM_LIT:7> , <NUM_LIT:7> ) ) return "<STR_LIT>" <EOL> if ( array1 . toList ( ) != listOf ( <NUM_LIT:7> , <NUM_LIT:7> , <NUM_LIT:7> ) ) return "<STR_LIT>" <EOL> return "<STR_LIT:OK>" <EOL> }


@ Test <EOL> fun testCancelInCollect ( )

= runTest ( expected = { it is CancellationException } ) { <EOL> expect ( <NUM_LIT:1> ) <EOL> flow { <EOL> expect ( <NUM_LIT:2> ) <EOL> emit ( <NUM_LIT:1> ) <EOL> expect ( <NUM_LIT:3> ) <EOL> hang { finish ( <NUM_LIT:6> ) } <EOL> } . idScoped ( ) . collect { value -> <EOL> expect ( <NUM_LIT:4> ) <EOL> assertEquals ( <NUM_LIT:1> , value ) <EOL> kotlin . coroutines . coroutineContext . cancel ( ) <EOL> expect ( <NUM_LIT:5> ) <EOL> } <EOL> expectUnreached ( ) <EOL> }


= runTest ( expected = { it is CancellationException } ) { <EOL> expect ( <NUM_LIT:1> ) <EOL> flow { <EOL> expect ( <NUM_LIT:2> ) <EOL> emit ( <NUM_LIT:1> ) <EOL> kotlin . coroutines . coroutineContext . cancel ( ) <EOL> expect ( <NUM_LIT:3> ) <EOL> } . idScoped ( ) . collect { value -> <EOL> finish ( <NUM_LIT:4> ) <EOL> assertEquals ( <NUM_LIT:1> , value ) <EOL> } <EOL> expectUnreached ( ) <EOL> }


private fun < T > Flow < T > . idScoped ( ) : Flow < T >

= flow { <EOL> coroutineScope { <EOL> val channel = produce { <EOL> collect { send ( it ) } <EOL> } <EOL> channel . consumeEach { <EOL> emit ( it ) <EOL> } <EOL> } <EOL> }

/**
 * This flow should be "identity" function with respect to cancellation.
 */


override fun report ( message : ( ) -> String , severity : ICReporter . ReportSeverity )

{ <EOL> buildReporter . report ( { "<STR_LIT>" } , severity ) <EOL> }


fun reportVerboseWithLimit ( maxLength : Int = <NUM_LIT> , message : ( ) -> String )

{ <EOL> debug { <EOL> message ( ) . let { <EOL> if ( it . length > maxLength ) { <EOL> it . substring ( <NUM_LIT:0> , maxLength ) + "<STR_LIT>" <EOL> } else it <EOL> } <EOL> } <EOL> }


inline fun < reified T > baz ( value : T ) : String

= "<STR_LIT:OK>" + value


{ <EOL> val f : ( Any ) -> String = :: baz <EOL> return f ( <NUM_LIT:1> ) <EOL> }


public inline fun < reified T > Foo . foo ( value : T ) : String

= <EOL> log + value


public inline fun < reified T > bar ( value : T ) : String

= <EOL> log + value


inline fun < reified T : String > qux ( value : T ) : String

= "<STR_LIT:OK>" + value


{ <EOL> val c = C ( ) <EOL> val cr : ( String ) -> String = c :: qux <EOL> return cr ( "<STR_LIT>" ) <EOL> }


inline fun < reified T : Any > ( ( Any ) -> String ) . cux ( value : T ) : String

= this ( value )


{ <EOL> val foo : ( Any ) -> String = ( { b : Any -> <EOL> val a : ( Any ) -> String = :: baz <EOL> a ( b ) <EOL> } ) :: cux <EOL> return foo ( <NUM_LIT:3> ) <EOL> }


inline fun < reified T , K , reified S > bak ( value1 : T , value2 : K , value3 : S ) : String

= "<STR_LIT:OK>" + value1 + value2 + value3


{ <EOL> val f : ( Any , Int , String ) -> String = :: bak <EOL> return f ( <NUM_LIT:1> , <NUM_LIT> , "<STR_LIT>" ) <EOL> }


inline fun < reified T , K > bal ( value1 : Array < K > , value2 : Array < T > ) : String

= "<STR_LIT:OK>" + value1 . joinToString ( ) + value2 . joinToString ( )


{ <EOL> val f : ( Array < Any > , Array < Int > ) -> String = :: bal <EOL> return f ( arrayOf ( "<STR_LIT>" , "<STR_LIT>" ) , arrayOf ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> }


public inline fun < reified T > E < T > . foo ( value : T ) : String

= "<STR_LIT:OK>" + value


inline fun < reified T2 > foo ( x : T1 , y : T2 ) : Any ?

= "<STR_LIT:OK>" + x + y


inline fun < reified T , K > bam ( value1 : K ? , value2 : T ? ) : String

= "<STR_LIT:OK>" + value1 . toString ( ) + value2 . toString ( )


{ <EOL> val f : ( T ? , String ? ) -> String = :: bam <EOL> return f ( null , "<STR_LIT:abc>" ) <EOL> }


inline fun < T > test11Impl ( ) : String

{ <EOL> val f : ( T ? , String ? ) -> String = :: bam <EOL> return f ( null , "<STR_LIT:def>" ) <EOL> }


= test11Impl < T > ( )


{ <EOL> val test1 = test ( ) <EOL> if ( test1 != "<STR_LIT>" ) return "<STR_LIT>" <EOL> val test2 = test2 ( ) <EOL> if ( test2 != "<STR_LIT>" ) return "<STR_LIT>" <EOL> val test3 = test3 ( ) <EOL> if ( test3 != "<STR_LIT>" ) return "<STR_LIT>" <EOL> val test4 = test4 ( ) <EOL> if ( test4 != "<STR_LIT>" ) return "<STR_LIT>" <EOL> val test5 = test5 ( ) <EOL> if ( test5 != "<STR_LIT>" ) return "<STR_LIT>" <EOL> val test6 = test6 ( ) <EOL> if ( test6 != "<STR_LIT>" ) return "<STR_LIT>" <EOL> val test7 = test7 ( ) <EOL> if ( test7 != "<STR_LIT>" ) return "<STR_LIT>" <EOL> val test8 = E < Int > ( ) . foo ( <NUM_LIT> ) <EOL> if ( test8 != "<STR_LIT>" ) return "<STR_LIT>" <EOL> val test9 = F < Int > ( ) . foo ( <NUM_LIT> , "<STR_LIT:hello>" ) <EOL> if ( test9 != "<STR_LIT>" ) return "<STR_LIT>" <EOL> val test10 = test10 < Int > ( ) <EOL> if ( test10 != "<STR_LIT>" ) return "<STR_LIT>" <EOL> val test11 = test11 < Int > ( ) <EOL> if ( test11 != "<STR_LIT>" ) return "<STR_LIT>" <EOL> return "<STR_LIT:OK>" <EOL> }


internal actual fun String . asUtf8ToByteArray ( ) : ByteArray

= commonAsUtf8ToByteArray ( )


external fun f4 ( __0 : `T$0` )


external fun f5 ( __0 : `T$0` , p : `T$0` , __2 : `T$0` )


external fun f6 ( __0 : `T$1` )


override fun transformFunctionAccess ( call : IrFunctionAccessExpression , doNotIntrinsify : Boolean ) : IrExpression

{ <EOL> return when ( call . symbol . owner . fqNameWhenAvailable ) { <EOL> FqName ( "<STR_LIT>" ) -> call . transformToIndexedRead ( ) <EOL> FqName ( "<STR_LIT>" ) -> call . transformToIndexedWrite ( ) <EOL> else -> call <EOL> } <EOL> }


{ <EOL> assert ( "<STR_LIT>" ) { this == t } <EOL> }


inline fun assert ( message : String , condition : ( ) -> Boolean )

{ <EOL> if ( ! condition ( ) ) <EOL> throw AssertionError ( message ) <EOL> }


{ <EOL> "<STR_LIT>" mustBe "<STR_LIT>" <EOL> return "<STR_LIT:OK>" <EOL> }


{ <EOL> for ( z in <NUM_LIT:1> .. <NUM_LIT:2> ) { <EOL> try { <EOL> try { <EOL> result += "<STR_LIT>" <EOL> break <EOL> } catch ( fail : Throwable ) { <EOL> result += "<STR_LIT>" <EOL> } <EOL> } finally { <EOL> result += "<STR_LIT>" <EOL> throw RuntimeException ( ) <EOL> } <EOL> } <EOL> }


{ <EOL> try { <EOL> test ( ) <EOL> return "<STR_LIT>" <EOL> } catch ( e : RuntimeException ) { <EOL> } <EOL> return if ( result == "<STR_LIT>" ) "<STR_LIT:OK>" else "<STR_LIT>" <EOL> }


{ <EOL> val file = createTempFile ( ) <EOL> assertTrue ( file . exists ( ) ) <EOL> file . deleteRecursively ( ) <EOL> assertFalse ( file . exists ( ) ) <EOL> file . createFile ( ) . writeText ( "<STR_LIT>" ) <EOL> assertTrue ( file . exists ( ) ) <EOL> file . deleteRecursively ( ) <EOL> assertFalse ( file . exists ( ) ) <EOL> file . deleteRecursively ( ) <EOL> }


{ <EOL> val dir = createTestFiles ( ) <EOL> assertTrue ( dir . exists ( ) ) <EOL> dir . deleteRecursively ( ) <EOL> assertFalse ( dir . exists ( ) ) <EOL> dir . deleteRecursively ( ) <EOL> }


@ Test <EOL> fun deleteNotExistingParent ( )

{ <EOL> val basedir = createTempDirectory ( ) . cleanupRecursively ( ) <EOL> basedir . resolve ( "<STR_LIT>" ) . deleteRecursively ( ) <EOL> basedir . resolve ( "<STR_LIT>" ) . deleteRecursively ( ) <EOL> }


private fun Path . walkIncludeDirectories ( ) : Sequence < Path >

= <EOL> this . walk ( PathWalkOption . INCLUDE_DIRECTORIES )


@ Test <EOL> fun deleteRestrictedRead ( )

{ <EOL> val basedir = createTestFiles ( ) . cleanupRecursively ( ) <EOL> val restrictedEmptyDir = basedir . resolve ( "<STR_LIT:6>" ) <EOL> val restrictedDir = basedir . resolve ( "<STR_LIT:1>" ) <EOL> val restrictedFile = basedir . resolve ( "<STR_LIT>" ) <EOL> withRestrictedRead ( restrictedEmptyDir , restrictedDir , restrictedFile ) { <EOL> val error = assertFailsWith < java . nio . file . FileSystemException > ( "<STR_LIT>" ) { <EOL> basedir . deleteRecursively ( ) <EOL> } <EOL> assertEquals ( <NUM_LIT:2> , error . suppressedExceptions . size ) <EOL> assertIs < java . nio . file . AccessDeniedException > ( error . suppressedExceptions [ <NUM_LIT:0> ] . let { it . cause ? : it } ) <EOL> assertIs < java . nio . file . AccessDeniedException > ( error . suppressedExceptions [ <NUM_LIT:1> ] . let { it . cause ? : it } ) <EOL> assertTrue ( restrictedEmptyDir . exists ( ) ) <EOL> assertTrue ( restrictedDir . exists ( ) ) <EOL> assertFalse ( restrictedFile . exists ( ) ) <EOL> restrictedEmptyDir . toFile ( ) . setReadable ( true ) <EOL> restrictedDir . toFile ( ) . setReadable ( true ) <EOL> testVisitedFiles ( listOf ( "<STR_LIT>" , "<STR_LIT:1>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:6>" ) , basedir . walkIncludeDirectories ( ) , basedir ) <EOL> basedir . deleteRecursively ( ) <EOL> } <EOL> }


@ Test <EOL> fun deleteRestrictedWrite ( )

{ <EOL> val basedir = createTestFiles ( ) . cleanupRecursively ( ) <EOL> val restrictedEmptyDir = basedir . resolve ( "<STR_LIT:6>" ) <EOL> val restrictedDir = basedir . resolve ( "<STR_LIT>" ) <EOL> val restrictedFile = basedir . resolve ( "<STR_LIT>" ) <EOL> withRestrictedWrite ( restrictedEmptyDir , restrictedDir , restrictedFile ) { <EOL> val error = assertFailsWith < java . nio . file . FileSystemException > ( "<STR_LIT>" ) { <EOL> basedir . deleteRecursively ( ) <EOL> } <EOL> when ( val accessDenied = error . suppressedExceptions . single ( ) ) { <EOL> is java . nio . file . AccessDeniedException -> { <EOL> assertEquals ( restrictedDir . resolve ( "<STR_LIT>" ) . toString ( ) , accessDenied . file ) <EOL> } <EOL> is java . nio . file . FileSystemException -> { <EOL> assertEquals ( restrictedDir . resolve ( "<STR_LIT>" ) . toString ( ) , accessDenied . file ) <EOL> assertIs < java . nio . file . AccessDeniedException > ( accessDenied . cause ) <EOL> } <EOL> else -> { <EOL> fail ( "<STR_LIT>" ) <EOL> } <EOL> } <EOL> assertFalse ( restrictedEmptyDir . exists ( ) ) <EOL> assertTrue ( restrictedDir . exists ( ) ) <EOL> assertTrue ( restrictedDir . resolve ( "<STR_LIT>" ) . exists ( ) ) <EOL> assertFalse ( restrictedFile . exists ( ) ) <EOL> } <EOL> }


@ Test <EOL> fun deleteBaseSymlinkToFile ( )

{ <EOL> val file = createTempFile ( ) . cleanup ( ) <EOL> val link = createTempDirectory ( ) . cleanupRecursively ( ) . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( file ) ? : return <EOL> link . deleteRecursively ( ) <EOL> assertFalse ( link . exists ( LinkOption . NOFOLLOW_LINKS ) ) <EOL> assertTrue ( file . exists ( ) ) <EOL> }


@ Test <EOL> fun deleteBaseSymlinkToDirectory ( )

{ <EOL> val dir = createTestFiles ( ) . cleanupRecursively ( ) <EOL> val link = createTempDirectory ( ) . cleanupRecursively ( ) . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( dir ) ? : return <EOL> link . deleteRecursively ( ) <EOL> assertFalse ( link . exists ( LinkOption . NOFOLLOW_LINKS ) ) <EOL> testVisitedFiles ( listOf ( "<STR_LIT>" ) + referenceFilenames , dir . walkIncludeDirectories ( ) , dir ) <EOL> }


@ Test <EOL> fun deleteSymlinkToFile ( )

{ <EOL> val file = createTempFile ( ) . cleanup ( ) <EOL> val dir = createTestFiles ( ) . cleanupRecursively ( ) . also { it . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( file ) ? : return } <EOL> dir . deleteRecursively ( ) <EOL> assertFalse ( dir . exists ( ) ) <EOL> assertTrue ( file . exists ( ) ) <EOL> }


@ Test <EOL> fun deleteSymlinkToDirectory ( )

{ <EOL> val dir1 = createTestFiles ( ) . cleanupRecursively ( ) <EOL> val dir2 = createTestFiles ( ) . cleanupRecursively ( ) . also { it . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( dir1 ) ? : return } <EOL> dir2 . deleteRecursively ( ) <EOL> assertFalse ( dir2 . exists ( ) ) <EOL> testVisitedFiles ( listOf ( "<STR_LIT>" ) + referenceFilenames , dir1 . walkIncludeDirectories ( ) , dir1 ) <EOL> }


@ Test <EOL> fun deleteParentSymlink ( )

{ <EOL> val dir1 = createTestFiles ( ) . cleanupRecursively ( ) <EOL> val dir2 = createTempDirectory ( ) . cleanupRecursively ( ) . also { it . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( dir1 ) ? : return } <EOL> dir2 . resolve ( "<STR_LIT>" ) . deleteRecursively ( ) <EOL> assertFalse ( dir1 . resolve ( "<STR_LIT>" ) . exists ( ) ) <EOL> dir2 . resolve ( "<STR_LIT>" ) . deleteRecursively ( ) <EOL> assertFalse ( dir1 . resolve ( "<STR_LIT>" ) . exists ( ) ) <EOL> }


@ Test <EOL> fun deleteSymlinkToSymlink ( )

{ <EOL> val dir = createTestFiles ( ) . cleanupRecursively ( ) <EOL> val link = createTempDirectory ( ) . cleanupRecursively ( ) . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( dir ) ? : return <EOL> val linkToLink = createTempDirectory ( ) . cleanupRecursively ( ) . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( link ) ? : return <EOL> linkToLink . deleteRecursively ( ) <EOL> assertFalse ( linkToLink . exists ( LinkOption . NOFOLLOW_LINKS ) ) <EOL> assertTrue ( link . exists ( LinkOption . NOFOLLOW_LINKS ) ) <EOL> testVisitedFiles ( listOf ( "<STR_LIT>" ) + referenceFilenames , dir . walkIncludeDirectories ( ) , dir ) <EOL> }


@ Test <EOL> fun deleteSymlinkCyclic ( )

{ <EOL> val basedir = createTestFiles ( ) . cleanupRecursively ( ) <EOL> val original = basedir . resolve ( "<STR_LIT:1>" ) <EOL> original . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( original ) ? : return <EOL> basedir . deleteRecursively ( ) <EOL> assertFalse ( basedir . exists ( ) ) <EOL> }


@ Test <EOL> fun deleteSymlinkCyclicWithTwo ( )

{ <EOL> val basedir = createTestFiles ( ) . cleanupRecursively ( ) <EOL> val dir8 = basedir . resolve ( "<STR_LIT>" ) <EOL> val dir2 = basedir . resolve ( "<STR_LIT>" ) <EOL> dir8 . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( dir2 ) ? : return <EOL> dir2 . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( dir8 ) ? : return <EOL> basedir . deleteRecursively ( ) <EOL> assertFalse ( basedir . exists ( ) ) <EOL> }


@ Test <EOL> fun deleteSymlinkPointingToItself ( )

{ <EOL> val basedir = createTempDirectory ( ) . cleanupRecursively ( ) <EOL> val link = basedir . resolve ( "<STR_LIT>" ) <EOL> link . tryCreateSymbolicLinkTo ( link ) ? : return <EOL> basedir . deleteRecursively ( ) <EOL> assertFalse ( basedir . exists ( ) ) <EOL> }


@ Test <EOL> fun deleteSymlinkTwoPointingToEachOther ( )

{ <EOL> val basedir = createTempDirectory ( ) . cleanupRecursively ( ) <EOL> val link1 = basedir . resolve ( "<STR_LIT>" ) <EOL> val link2 = basedir . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( link1 ) ? : return <EOL> link1 . tryCreateSymbolicLinkTo ( link2 ) ? : return <EOL> basedir . deleteRecursively ( ) <EOL> assertFalse ( basedir . exists ( ) ) <EOL> }


private fun compareFiles ( src : Path , dst : Path , message : String ? = null )

{ <EOL> assertTrue ( dst . exists ( ) ) <EOL> assertEquals ( src . isRegularFile ( ) , dst . isRegularFile ( ) , message ) <EOL> assertEquals ( src . isDirectory ( ) , dst . isDirectory ( ) , message ) <EOL> if ( dst . isRegularFile ( ) ) { <EOL> assertTrue ( src . readBytes ( ) . contentEquals ( dst . readBytes ( ) ) , message ) <EOL> } <EOL> }


private fun compareDirectories ( src : Path , dst : Path )

{ <EOL> for ( srcFile in src . walkIncludeDirectories ( ) ) { <EOL> val dstFile = dst . resolve ( srcFile . relativeTo ( src ) ) <EOL> compareFiles ( srcFile , dstFile ) <EOL> } <EOL> }


{ <EOL> val src = createTempFile ( ) . cleanup ( ) . also { it . writeText ( "<STR_LIT:hello>" ) } <EOL> val dst = createTempDirectory ( ) . cleanupRecursively ( ) . resolve ( "<STR_LIT>" ) <EOL> val copyResult = src . copyToRecursively ( dst , followLinks = false ) <EOL> assertEquals ( dst , copyResult ) <EOL> compareFiles ( src , dst ) <EOL> dst . writeText ( "<STR_LIT>" ) <EOL> assertFailsWith < java . nio . file . FileAlreadyExistsException > { <EOL> src . copyToRecursively ( dst , followLinks = false ) <EOL> } <EOL> assertEquals ( "<STR_LIT>" , dst . readText ( ) ) <EOL> src . copyToRecursively ( dst , followLinks = false , overwrite = true ) <EOL> compareFiles ( src , dst ) <EOL> }


@ Test <EOL> fun copyFileToDirectory ( )

{ <EOL> val src = createTempFile ( ) . cleanup ( ) . also { it . writeText ( "<STR_LIT:hello>" ) } <EOL> val dst = createTestFiles ( ) . cleanupRecursively ( ) <EOL> assertFailsWith < java . nio . file . FileAlreadyExistsException > { <EOL> src . copyToRecursively ( dst , followLinks = false ) <EOL> } <EOL> assertTrue ( dst . isDirectory ( ) ) <EOL> assertFailsWith < java . nio . file . DirectoryNotEmptyException > { <EOL> src . copyToRecursively ( dst , followLinks = false ) { source , target -> <EOL> source . copyTo ( target , overwrite = true ) <EOL> CopyActionResult . CONTINUE <EOL> } <EOL> } <EOL> assertTrue ( dst . isDirectory ( ) ) <EOL> val copyResult = src . copyToRecursively ( dst , followLinks = false , overwrite = true ) <EOL> assertEquals ( dst , copyResult ) <EOL> compareFiles ( src , dst ) <EOL> }


private fun Path . relativePathString ( base : Path ) : String

{ <EOL> return relativeToOrSelf ( base ) . invariantSeparatorsPathString <EOL> }


@ Test <EOL> fun copyDirectoryToDirectory ( )

{ <EOL> val src = createTestFiles ( ) . cleanupRecursively ( ) <EOL> val dst = createTempDirectory ( ) . cleanupRecursively ( ) . resolve ( "<STR_LIT>" ) <EOL> val copyResult = src . copyToRecursively ( dst , followLinks = false ) <EOL> assertEquals ( dst , copyResult ) <EOL> compareDirectories ( src , dst ) <EOL> src . resolve ( "<STR_LIT>" ) . writeText ( "<STR_LIT:hello>" ) <EOL> dst . resolve ( "<STR_LIT:10>" ) . createDirectory ( ) <EOL> val conflictingFiles = mutableListOf < String > ( ) <EOL> src . copyToRecursively ( dst , followLinks = false , onError = { source , _ , exception -> <EOL> assertIs < java . nio . file . FileAlreadyExistsException > ( exception ) <EOL> conflictingFiles . add ( source . relativePathString ( src ) ) <EOL> OnErrorResult . SKIP_SUBTREE <EOL> } ) <EOL> assertEquals ( referenceFilesOnly . sorted ( ) , conflictingFiles . sorted ( ) ) <EOL> assertTrue ( dst . resolve ( "<STR_LIT>" ) . readText ( ) . isEmpty ( ) ) <EOL> src . copyToRecursively ( dst , followLinks = false , overwrite = true ) <EOL> compareDirectories ( src , dst ) <EOL> assertTrue ( dst . resolve ( "<STR_LIT:10>" ) . exists ( ) ) <EOL> }


@ Test <EOL> fun copyDirectoryToFile ( )

{ <EOL> val src = createTestFiles ( ) . cleanupRecursively ( ) <EOL> val dst = createTempFile ( ) . cleanupRecursively ( ) . also { it . writeText ( "<STR_LIT:hello>" ) } <EOL> val existsException = assertFailsWith < java . nio . file . FileAlreadyExistsException > { <EOL> src . copyToRecursively ( dst , followLinks = false ) <EOL> } <EOL> assertEquals ( dst . toString ( ) , existsException . file ) <EOL> assertTrue ( dst . isRegularFile ( ) ) <EOL> src . copyToRecursively ( dst , followLinks = false , overwrite = true ) <EOL> compareDirectories ( src , dst ) <EOL> }


@ Test <EOL> fun copyNonExistentSource ( )

{ <EOL> val src = createTempDirectory ( ) . also { it . deleteExisting ( ) } <EOL> val dst = createTempDirectory ( ) <EOL> assertFailsWith < java . nio . file . NoSuchFileException > { <EOL> src . copyToRecursively ( dst , followLinks = false ) <EOL> } <EOL> dst . deleteExisting ( ) <EOL> assertFailsWith < java . nio . file . NoSuchFileException > { <EOL> src . copyToRecursively ( dst , followLinks = false ) <EOL> } <EOL> }


@ Test <EOL> fun copyNonExistentDestinationParent ( )

{ <EOL> val src = createTempDirectory ( ) . cleanupRecursively ( ) <EOL> val dst = createTempDirectory ( ) . cleanupRecursively ( ) . resolve ( "<STR_LIT>" ) <EOL> assertFalse ( dst . parent . exists ( ) ) <EOL> src . copyToRecursively ( dst , followLinks = false , onError = { source , target , exception -> <EOL> assertIs < java . nio . file . NoSuchFileException > ( exception ) <EOL> assertEquals ( src , source ) <EOL> assertEquals ( dst , target ) <EOL> assertEquals ( dst . toString ( ) , exception . file ) <EOL> OnErrorResult . SKIP_SUBTREE <EOL> } ) <EOL> src . copyToRecursively ( dst . createParentDirectories ( ) , followLinks = false ) <EOL> }


@ Test <EOL> fun copyRestrictedReadInSource ( )

{ <EOL> val src = createTestFiles ( ) . cleanupRecursively ( ) <EOL> val dst = createTempDirectory ( ) . cleanupRecursively ( ) <EOL> val restrictedDir = src . resolve ( "<STR_LIT>" ) <EOL> val restrictedFile = src . resolve ( "<STR_LIT>" ) <EOL> withRestrictedRead ( restrictedDir , restrictedFile , alsoReset = listOf ( dst . resolve ( "<STR_LIT>" ) , dst . resolve ( "<STR_LIT>" ) ) ) { <EOL> src . copyToRecursively ( dst , followLinks = false , onError = { source , _ , exception -> <EOL> assertIs < java . nio . file . AccessDeniedException > ( exception ) <EOL> assertEquals ( source . toString ( ) , exception . file ) <EOL> assertEquals ( "<STR_LIT>" , source . relativePathString ( src ) ) <EOL> OnErrorResult . SKIP_SUBTREE <EOL> } ) { source , target -> <EOL> try { <EOL> source . copyToIgnoringExistingDirectory ( target , followLinks = false ) <EOL> } catch ( exception : Throwable ) { <EOL> assertIs < java . nio . file . AccessDeniedException > ( exception ) <EOL> assertEquals ( source . toString ( ) , exception . file ) <EOL> assertEquals ( "<STR_LIT>" , source . relativePathString ( src ) ) <EOL> } <EOL> CopyActionResult . CONTINUE <EOL> } <EOL> assertFalse ( dst . resolve ( "<STR_LIT>" ) . exists ( ) ) <EOL> assertFalse ( dst . resolve ( "<STR_LIT>" ) . exists ( ) ) <EOL> } <EOL> }


@ Test <EOL> fun copyRestrictedWriteInSource ( )

{ <EOL> val src = createTestFiles ( ) . cleanupRecursively ( ) <EOL> val dst = createTempDirectory ( ) . cleanupRecursively ( ) <EOL> val restrictedDir = src . resolve ( "<STR_LIT>" ) <EOL> val restrictedFile = src . resolve ( "<STR_LIT>" ) <EOL> withRestrictedWrite ( restrictedDir , restrictedFile , alsoReset = listOf ( dst . resolve ( "<STR_LIT>" ) , dst . resolve ( "<STR_LIT>" ) ) ) { <EOL> val accessDeniedFiles = mutableListOf < String > ( ) <EOL> src . copyToRecursively ( dst , followLinks = false , onError = { _ , target , exception -> <EOL> assertIs < java . nio . file . AccessDeniedException > ( exception ) <EOL> assertEquals ( target . toString ( ) , exception . file ) <EOL> accessDeniedFiles . add ( target . relativePathString ( dst ) ) <EOL> OnErrorResult . SKIP_SUBTREE <EOL> } ) <EOL> assertEquals ( listOf ( "<STR_LIT>" , "<STR_LIT>" ) , accessDeniedFiles . sorted ( ) ) <EOL> assertTrue ( dst . resolve ( "<STR_LIT>" ) . exists ( ) ) <EOL> assertFalse ( dst . resolve ( "<STR_LIT>" ) . isWritable ( ) ) <EOL> assertTrue ( dst . resolve ( "<STR_LIT>" ) . exists ( ) ) <EOL> assertFalse ( dst . resolve ( "<STR_LIT>" ) . isWritable ( ) ) <EOL> } <EOL> }


@ Test <EOL> fun copyRestrictedWriteInDestination ( )

{ <EOL> val src = createTestFiles ( ) . cleanupRecursively ( ) <EOL> val dst = createTestFiles ( ) . cleanupRecursively ( ) <EOL> src . resolve ( "<STR_LIT>" ) . writeText ( "<STR_LIT:hello>" ) <EOL> src . resolve ( "<STR_LIT>" ) . writeText ( "<STR_LIT>" ) <EOL> val restrictedDir = dst . resolve ( "<STR_LIT>" ) <EOL> val restrictedFile = dst . resolve ( "<STR_LIT>" ) <EOL> withRestrictedWrite ( restrictedDir , restrictedFile ) { <EOL> val accessDeniedFiles = mutableListOf < String > ( ) <EOL> src . copyToRecursively ( dst , followLinks = false , overwrite = true , onError = { _ , target , exception -> <EOL> assertIs < java . nio . file . AccessDeniedException > ( exception ) <EOL> assertEquals ( target . toString ( ) , exception . file ) <EOL> accessDeniedFiles . add ( target . relativePathString ( dst ) ) <EOL> OnErrorResult . SKIP_SUBTREE <EOL> } ) <EOL> assertEquals ( listOf ( "<STR_LIT>" , "<STR_LIT>" ) , accessDeniedFiles . sorted ( ) ) <EOL> assertNotEquals ( src . resolve ( "<STR_LIT>" ) . readText ( ) , dst . resolve ( "<STR_LIT>" ) . readText ( ) ) <EOL> assertEquals ( src . resolve ( "<STR_LIT>" ) . readText ( ) , dst . resolve ( "<STR_LIT>" ) . readText ( ) ) <EOL> } <EOL> }


@ Test <EOL> fun copyBrokenBaseSymlink ( )

{ <EOL> val basedir = createTempDirectory ( ) . cleanupRecursively ( ) <EOL> val target = basedir . resolve ( "<STR_LIT>" ) <EOL> val link = basedir . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( target ) ? : return <EOL> val dst = basedir . resolve ( "<STR_LIT>" ) <EOL> link . copyToRecursively ( dst , followLinks = false ) <EOL> assertTrue ( dst . isSymbolicLink ( ) ) <EOL> assertTrue ( dst . exists ( LinkOption . NOFOLLOW_LINKS ) ) <EOL> assertFalse ( dst . exists ( ) ) <EOL> assertFailsWith < java . nio . file . FileAlreadyExistsException > { <EOL> link . copyToRecursively ( dst , followLinks = false ) <EOL> } <EOL> dst . deleteExisting ( ) <EOL> assertFailsWith < java . nio . file . NoSuchFileException > { <EOL> link . copyToRecursively ( dst , followLinks = true ) <EOL> } <EOL> assertFalse ( dst . exists ( LinkOption . NOFOLLOW_LINKS ) ) <EOL> }


{ <EOL> val src = createTestFiles ( ) . cleanupRecursively ( ) <EOL> val dst = createTempDirectory ( ) . cleanupRecursively ( ) . resolve ( "<STR_LIT>" ) <EOL> val target = createTempDirectory ( ) . cleanupRecursively ( ) . resolve ( "<STR_LIT>" ) <EOL> src . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( target ) ? : return <EOL> val dstLink = dst . resolve ( "<STR_LIT>" ) <EOL> src . copyToRecursively ( dst , followLinks = false ) <EOL> assertTrue ( dstLink . isSymbolicLink ( ) ) <EOL> assertTrue ( dstLink . exists ( LinkOption . NOFOLLOW_LINKS ) ) <EOL> assertFalse ( dstLink . exists ( ) ) <EOL> dst . deleteRecursively ( ) <EOL> assertFailsWith < java . nio . file . NoSuchFileException > { <EOL> src . copyToRecursively ( dst , followLinks = true ) <EOL> } <EOL> assertFalse ( dstLink . exists ( LinkOption . NOFOLLOW_LINKS ) ) <EOL> }


@ Test <EOL> fun copyBaseSymlinkPointingToFile ( )

{ <EOL> val src = createTempFile ( ) . cleanup ( ) . also { it . writeText ( "<STR_LIT:hello>" ) } <EOL> val link = createTempDirectory ( ) . cleanupRecursively ( ) . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( src ) ? : return <EOL> val dst = createTempDirectory ( ) . cleanupRecursively ( ) . resolve ( "<STR_LIT>" ) <EOL> link . copyToRecursively ( dst , followLinks = false ) <EOL> compareFiles ( link , dst ) <EOL> dst . deleteExisting ( ) <EOL> link . copyToRecursively ( dst , followLinks = true ) <EOL> compareFiles ( src , dst ) <EOL> }


@ Test <EOL> fun copyBaseSymlinkPointingToDirectory ( )

{ <EOL> val src = createTestFiles ( ) . cleanupRecursively ( ) <EOL> val link = createTempDirectory ( ) . cleanupRecursively ( ) . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( src ) ? : return <EOL> val dst = createTempDirectory ( ) . cleanupRecursively ( ) . resolve ( "<STR_LIT>" ) <EOL> link . copyToRecursively ( dst , followLinks = false ) <EOL> compareFiles ( link , dst ) <EOL> dst . deleteExisting ( ) <EOL> link . copyToRecursively ( dst , followLinks = true ) <EOL> compareDirectories ( src , dst ) <EOL> }


@ Test <EOL> fun copySymlinkPointingToDirectory ( )

{ <EOL> val symlinkTarget = createTestFiles ( ) . cleanupRecursively ( ) <EOL> val src = createTestFiles ( ) . cleanupRecursively ( ) . also { it . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( symlinkTarget ) ? : return } <EOL> val dst = createTempDirectory ( ) . cleanupRecursively ( ) . resolve ( "<STR_LIT>" ) <EOL> src . copyToRecursively ( dst , followLinks = false ) <EOL> val srcContent = listOf ( "<STR_LIT>" , "<STR_LIT>" ) + referenceFilenames <EOL> testVisitedFiles ( srcContent , dst . walkIncludeDirectories ( ) , dst ) <EOL> dst . deleteRecursively ( ) <EOL> src . copyToRecursively ( dst , followLinks = true ) <EOL> val expectedDstContent = srcContent + referenceFilenames . map { "<STR_LIT>" } <EOL> testVisitedFiles ( expectedDstContent , dst . walkIncludeDirectories ( ) , dst ) <EOL> }


@ Test <EOL> fun copyIgnoreExistingDirectoriesFollowLinks ( )

{ <EOL> val src = createTestFiles ( ) . cleanupRecursively ( ) <EOL> val symlinkTarget = createTempDirectory ( ) . cleanupRecursively ( ) <EOL> val dst = createTempDirectory ( ) . cleanupRecursively ( ) . also { <EOL> it . resolve ( "<STR_LIT:1>" ) . createDirectory ( ) <EOL> it . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( symlinkTarget ) ? : return <EOL> } <EOL> src . copyToRecursively ( dst , followLinks = true , onError = { source , target , exception -> <EOL> assertIs < java . nio . file . FileAlreadyExistsException > ( exception ) <EOL> assertEquals ( src . resolve ( "<STR_LIT>" ) , source ) <EOL> assertEquals ( dst . resolve ( "<STR_LIT>" ) , target ) <EOL> assertEquals ( target . toString ( ) , exception . file ) <EOL> OnErrorResult . SKIP_SUBTREE <EOL> } ) <EOL> assertTrue ( dst . resolve ( "<STR_LIT>" ) . isSymbolicLink ( ) ) <EOL> assertTrue ( symlinkTarget . listDirectoryEntries ( ) . isEmpty ( ) ) <EOL> src . copyToRecursively ( dst , followLinks = true , overwrite = true ) <EOL> assertFalse ( dst . resolve ( "<STR_LIT>" ) . isSymbolicLink ( ) ) <EOL> assertTrue ( symlinkTarget . listDirectoryEntries ( ) . isEmpty ( ) ) <EOL> }


@ Test <EOL> fun copyIgnoreExistingDirectoriesNoFollowLinks ( )

{ <EOL> val src = createTestFiles ( ) . cleanupRecursively ( ) <EOL> val symlinkTarget = createTempDirectory ( ) . cleanupRecursively ( ) <EOL> val dst = createTempDirectory ( ) . cleanupRecursively ( ) . also { <EOL> it . resolve ( "<STR_LIT:1>" ) . createDirectory ( ) <EOL> it . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( symlinkTarget ) ? : return <EOL> } <EOL> src . copyToRecursively ( dst , followLinks = false , onError = { source , target , exception -> <EOL> assertIs < java . nio . file . FileAlreadyExistsException > ( exception ) <EOL> assertEquals ( src . resolve ( "<STR_LIT>" ) , source ) <EOL> assertEquals ( dst . resolve ( "<STR_LIT>" ) , target ) <EOL> assertEquals ( target . toString ( ) , exception . file ) <EOL> OnErrorResult . SKIP_SUBTREE <EOL> } ) <EOL> assertTrue ( dst . resolve ( "<STR_LIT>" ) . isSymbolicLink ( ) ) <EOL> assertTrue ( symlinkTarget . listDirectoryEntries ( ) . isEmpty ( ) ) <EOL> src . copyToRecursively ( dst , followLinks = false , overwrite = true ) <EOL> assertFalse ( dst . resolve ( "<STR_LIT>" ) . isSymbolicLink ( ) ) <EOL> assertTrue ( symlinkTarget . listDirectoryEntries ( ) . isEmpty ( ) ) <EOL> }


{ <EOL> val source = createTestFiles ( ) . cleanupRecursively ( ) <EOL> val linkToSource = createTempDirectory ( ) . cleanupRecursively ( ) . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( source ) ? : return <EOL> val sources = listOf ( source to referenceFilenames , linkToSource . resolve ( "<STR_LIT>" ) to listOf ( "<STR_LIT>" ) , linkToSource . resolve ( "<STR_LIT>" ) to listOf ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> for ( ( src , srcContent ) in sources ) { <EOL> for ( followLinks in listOf ( false , true ) ) { <EOL> val target = createTempDirectory ( ) . cleanupRecursively ( ) . also { it . resolve ( "<STR_LIT>" ) . createDirectories ( ) } <EOL> val linkToTarget = createTempDirectory ( ) . cleanupRecursively ( ) . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( target ) ? : return <EOL> val targets = listOf ( target to listOf ( "<STR_LIT:a>" , "<STR_LIT>" ) , linkToTarget . resolve ( "<STR_LIT:a>" ) to listOf ( "<STR_LIT:b>" ) , linkToTarget . resolve ( "<STR_LIT>" ) to listOf ( ) ) <EOL> for ( ( dst , dstContent ) in targets ) { <EOL> src . copyToRecursively ( dst , followLinks = followLinks ) <EOL> val expectedDstContent = listOf ( "<STR_LIT>" ) + dstContent + srcContent <EOL> testVisitedFiles ( expectedDstContent , dst . walkIncludeDirectories ( ) , dst ) <EOL> } <EOL> } <EOL> } <EOL> }


@ Test <EOL> fun copySymlinkToSymlink ( )

{ <EOL> val src = createTestFiles ( ) . cleanupRecursively ( ) <EOL> val link = createTempDirectory ( ) . cleanupRecursively ( ) . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( src ) ? : return <EOL> val linkToLink = createTempDirectory ( ) . cleanupRecursively ( ) . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( link ) ? : return <EOL> val dst = createTempDirectory ( ) . cleanupRecursively ( ) . resolve ( "<STR_LIT>" ) <EOL> linkToLink . copyToRecursively ( dst , followLinks = true ) <EOL> testVisitedFiles ( listOf ( "<STR_LIT>" ) + referenceFilenames , dst . walkIncludeDirectories ( ) , dst ) <EOL> }


{ <EOL> val src = createTestFiles ( ) . cleanupRecursively ( ) <EOL> val original = src . resolve ( "<STR_LIT:1>" ) <EOL> original . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( original ) ? : return <EOL> val dst = createTempDirectory ( ) . cleanupRecursively ( ) . resolve ( "<STR_LIT>" ) <EOL> src . copyToRecursively ( dst , followLinks = true , onError = { source , _ , exception -> <EOL> assertIs < java . nio . file . FileSystemLoopException > ( exception ) <EOL> assertEquals ( src . resolve ( "<STR_LIT>" ) , source ) <EOL> assertEquals ( source . toString ( ) , exception . file ) <EOL> OnErrorResult . SKIP_SUBTREE <EOL> } ) <EOL> testVisitedFiles ( listOf ( "<STR_LIT>" ) + referenceFilenames , dst . walkIncludeDirectories ( ) , dst ) <EOL> }


@ Test <EOL> fun copySymlinkCyclicWithTwo ( )

{ <EOL> val src = createTestFiles ( ) . cleanupRecursively ( ) <EOL> val dir8 = src . resolve ( "<STR_LIT>" ) <EOL> val dir2 = src . resolve ( "<STR_LIT>" ) <EOL> dir8 . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( dir2 ) ? : return <EOL> dir2 . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( dir8 ) ? : return <EOL> val dst = createTempDirectory ( ) . cleanupRecursively ( ) . resolve ( "<STR_LIT>" ) <EOL> val loops = mutableListOf < String > ( ) <EOL> src . copyToRecursively ( dst , followLinks = true , onError = { source , _ , exception -> <EOL> assertIs < java . nio . file . FileSystemLoopException > ( exception ) <EOL> assertEquals ( source . toString ( ) , exception . file ) <EOL> loops . add ( source . relativePathString ( src ) ) <EOL> OnErrorResult . SKIP_SUBTREE <EOL> } ) <EOL> assertEquals ( listOf ( "<STR_LIT>" , "<STR_LIT>" ) , loops . sorted ( ) ) <EOL> val expected = listOf ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) + referenceFilenames <EOL> testVisitedFiles ( expected , dst . walkIncludeDirectories ( ) , dst ) <EOL> }


@ Test <EOL> fun copySymlinkPointingToItself ( )

{ <EOL> val src = createTempDirectory ( ) . cleanupRecursively ( ) <EOL> val link = src . resolve ( "<STR_LIT>" ) <EOL> link . tryCreateSymbolicLinkTo ( link ) ? : return <EOL> val dst = createTempDirectory ( ) . cleanupRecursively ( ) . resolve ( "<STR_LIT>" ) <EOL> assertFailsWith < java . nio . file . FileSystemException > { <EOL> src . copyToRecursively ( dst , followLinks = true ) <EOL> } <EOL> }


@ Test <EOL> fun copySymlinkTwoPointingToEachOther ( )

{ <EOL> val src = createTempDirectory ( ) . cleanupRecursively ( ) <EOL> val link1 = src . resolve ( "<STR_LIT>" ) <EOL> val link2 = src . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( link1 ) ? : return <EOL> link1 . tryCreateSymbolicLinkTo ( link2 ) ? : return <EOL> val dst = createTempDirectory ( ) . cleanupRecursively ( ) . resolve ( "<STR_LIT>" ) <EOL> assertFailsWith < java . nio . file . FileSystemException > { <EOL> src . copyToRecursively ( dst , followLinks = true ) <EOL> } <EOL> }


@ Test <EOL> fun copyWithNestedCopyToRecursively ( )

{ <EOL> val src = createTestFiles ( ) . cleanupRecursively ( ) <EOL> val dst = createTempDirectory ( ) . cleanupRecursively ( ) . resolve ( "<STR_LIT>" ) <EOL> val nested = createTestFiles ( ) . cleanupRecursively ( ) <EOL> src . copyToRecursively ( dst , followLinks = false ) { source , target -> <EOL> if ( source . name == "<STR_LIT:2>" ) { <EOL> nested . copyToRecursively ( target , followLinks = false ) <EOL> } else { <EOL> source . copyToIgnoringExistingDirectory ( target , followLinks = false ) <EOL> } <EOL> CopyActionResult . CONTINUE <EOL> } <EOL> val expected = listOf ( "<STR_LIT>" ) + referenceFilenames + referenceFilenames . map { "<STR_LIT>" } <EOL> testVisitedFiles ( expected , dst . walkIncludeDirectories ( ) , dst ) <EOL> }


@ Test <EOL> fun copyWithSkipSubtree ( )

{ <EOL> val src = createTestFiles ( ) . cleanupRecursively ( ) <EOL> val dst = createTempDirectory ( ) . cleanupRecursively ( ) . resolve ( "<STR_LIT>" ) <EOL> src . copyToRecursively ( dst , followLinks = false ) { source , target -> <EOL> source . copyToIgnoringExistingDirectory ( target , followLinks = false ) <EOL> if ( source . name == "<STR_LIT:3>" || source . name == "<STR_LIT>" ) { <EOL> CopyActionResult . SKIP_SUBTREE <EOL> } else { <EOL> CopyActionResult . CONTINUE <EOL> } <EOL> } <EOL> val copied3 = dst . resolve ( "<STR_LIT>" ) . exists ( ) <EOL> val copied9 = dst . resolve ( "<STR_LIT>" ) . exists ( ) <EOL> assertTrue ( copied3 && copied9 ) <EOL> assertTrue ( dst . resolve ( "<STR_LIT>" ) . listDirectoryEntries ( ) . isEmpty ( ) ) <EOL> }


{ <EOL> val src = createTestFiles ( ) . cleanupRecursively ( ) <EOL> val dst = createTempDirectory ( ) . cleanupRecursively ( ) . resolve ( "<STR_LIT>" ) <EOL> src . copyToRecursively ( dst , followLinks = false ) { source , target -> <EOL> source . copyToIgnoringExistingDirectory ( target , followLinks = false ) <EOL> if ( source . name == "<STR_LIT:3>" || source . name == "<STR_LIT>" ) { <EOL> CopyActionResult . TERMINATE <EOL> } else { <EOL> CopyActionResult . CONTINUE <EOL> } <EOL> } <EOL> val copied3 = dst . resolve ( "<STR_LIT>" ) . exists ( ) <EOL> val copied9 = dst . resolve ( "<STR_LIT>" ) . exists ( ) <EOL> assertTrue ( copied3 || copied9 ) <EOL> assertFalse ( copied3 && copied9 ) <EOL> }


@ Test <EOL> fun copyFailureWithTerminate ( )

{ <EOL> val src = createTestFiles ( ) . cleanupRecursively ( ) <EOL> val dst = createTempDirectory ( ) . cleanupRecursively ( ) . resolve ( "<STR_LIT>" ) <EOL> src . copyToRecursively ( dst , followLinks = false , onError = { source , _ , exception -> <EOL> assertIs < IllegalArgumentException > ( exception ) <EOL> assertTrue ( source . name == "<STR_LIT:3>" || source . name == "<STR_LIT>" ) <EOL> OnErrorResult . TERMINATE <EOL> } ) { source , target -> <EOL> source . copyToIgnoringExistingDirectory ( target , followLinks = false ) <EOL> if ( source . name == "<STR_LIT:3>" || source . name == "<STR_LIT>" ) throw IllegalArgumentException ( ) <EOL> CopyActionResult . CONTINUE <EOL> } <EOL> val copied3 = dst . resolve ( "<STR_LIT>" ) . exists ( ) <EOL> val copied9 = dst . resolve ( "<STR_LIT>" ) . exists ( ) <EOL> assertTrue ( copied3 || copied9 ) <EOL> assertFalse ( copied3 && copied9 ) <EOL> }


@ Test <EOL> fun copyIntoSourceDirectory ( )

{ <EOL> val source = createTestFiles ( ) . cleanupRecursively ( ) <EOL> val linkToSource = createTempDirectory ( ) . cleanupRecursively ( ) . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( source ) ? : return <EOL> val sources = listOf ( source to source , linkToSource . resolve ( "<STR_LIT>" ) to source . resolve ( "<STR_LIT>" ) , linkToSource . resolve ( "<STR_LIT>" ) to source . resolve ( "<STR_LIT>" ) ) <EOL> for ( ( src , resolvedSrc ) in sources ) { <EOL> val linkToSrc = createTempDirectory ( ) . cleanupRecursively ( ) . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( resolvedSrc ) ? : return <EOL> val targets = listOf ( linkToSrc . resolve ( "<STR_LIT:a>" ) . createDirectory ( ) , linkToSrc . resolve ( "<STR_LIT>" ) . createDirectories ( ) ) <EOL> for ( followLinks in listOf ( false , true ) ) { <EOL> assertFailsWith < java . nio . file . FileAlreadyExistsException > { <EOL> src . copyToRecursively ( linkToSrc , followLinks = followLinks ) <EOL> } <EOL> for ( dst in targets ) { <EOL> val error = assertFailsWith < java . nio . file . FileSystemException > { <EOL> src . copyToRecursively ( dst , followLinks = followLinks ) <EOL> } <EOL> assertEquals ( "<STR_LIT>" , error . reason ) <EOL> } <EOL> } <EOL> } <EOL> }


{ <EOL> val src = createTempDirectory ( ) . cleanupRecursively ( ) <EOL> src . resolve ( "<STR_LIT>" ) . writeText ( "<STR_LIT>" ) <EOL> val dst = src . resolve ( "<STR_LIT:x>" ) <EOL> val error = assertFailsWith < java . nio . file . FileSystemException > { <EOL> src . copyToRecursively ( dst , followLinks = false ) <EOL> } <EOL> assertEquals ( "<STR_LIT>" , error . reason ) <EOL> }


{ <EOL> for ( src in listOf ( createTempFile ( ) . cleanupRecursively ( ) , createTestFiles ( ) . cleanupRecursively ( ) ) ) { <EOL> src . copyToRecursively ( src , followLinks = false ) <EOL> val link = createTempDirectory ( ) . cleanupRecursively ( ) . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( src ) ? : return <EOL> val error = assertFailsWith < java . nio . file . FileAlreadyExistsException > { <EOL> link . copyToRecursively ( src , followLinks = false ) <EOL> } <EOL> assertEquals ( src . toString ( ) , error . file ) <EOL> link . copyToRecursively ( src , followLinks = true ) <EOL> for ( followLinks in listOf ( false , true ) ) { <EOL> assertFailsWith < java . nio . file . FileAlreadyExistsException > { <EOL> src . copyToRecursively ( link , followLinks = followLinks ) <EOL> } <EOL> } <EOL> } <EOL> }


@ Test <EOL> fun copyDstLinkPointingToSrc ( )

{ <EOL> for ( followLinks in listOf ( false , true ) ) { <EOL> val root = createTempDirectory ( ) . cleanupRecursively ( ) <EOL> val src = root . resolve ( "<STR_LIT:src>" ) . createFile ( ) <EOL> val dstLink = root . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( src ) ? : return <EOL> assertTrue ( src . isSameFileAs ( dstLink ) ) <EOL> assertTrue ( dstLink . isSameFileAs ( src ) ) <EOL> assertFailsWith < FileAlreadyExistsException > { <EOL> src . copyToRecursively ( dstLink , followLinks = followLinks ) <EOL> } <EOL> assertTrue ( dstLink . isSymbolicLink ( ) ) <EOL> } <EOL> }


@ Test <EOL> fun copyDstLinkPointingToSrcOverwrite ( )

{ <EOL> for ( followLinks in listOf ( false , true ) ) { <EOL> val root = createTempDirectory ( ) . cleanupRecursively ( ) <EOL> val src = root . resolve ( "<STR_LIT:src>" ) . createFile ( ) <EOL> val dstLink = root . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( src ) ? : return <EOL> src . copyToRecursively ( dstLink , followLinks = followLinks , overwrite = true ) <EOL> assertFalse ( dstLink . isSymbolicLink ( ) ) <EOL> } <EOL> }


@ Test <EOL> fun copySrcLinkAndDstLinkPointingToSameFile ( )

{ <EOL> for ( followLinks in listOf ( false , true ) ) { <EOL> val root = createTempDirectory ( ) . cleanupRecursively ( ) <EOL> val original = root . resolve ( "<STR_LIT>" ) . createFile ( ) <EOL> val srcLink = root . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( original ) ? : return <EOL> val dstLink = root . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( original ) ? : return <EOL> assertTrue ( srcLink . isSameFileAs ( dstLink ) ) <EOL> assertTrue ( dstLink . isSameFileAs ( srcLink ) ) <EOL> assertFailsWith < FileAlreadyExistsException > { <EOL> srcLink . copyToRecursively ( dstLink , followLinks = followLinks ) <EOL> } <EOL> assertTrue ( dstLink . isSymbolicLink ( ) ) <EOL> } <EOL> }


@ Test <EOL> fun copySrcLinkAndDstLinkPointingToSameFileOverwrite ( )

{ <EOL> for ( followLinks in listOf ( false , true ) ) { <EOL> val root = createTempDirectory ( ) . cleanupRecursively ( ) <EOL> val original = root . resolve ( "<STR_LIT>" ) . createFile ( ) <EOL> val srcLink = root . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( original ) ? : return <EOL> val dstLink = root . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( original ) ? : return <EOL> srcLink . copyToRecursively ( dstLink , followLinks = followLinks , overwrite = true ) <EOL> if ( ! followLinks ) { <EOL> assertTrue ( dstLink . isSymbolicLink ( ) ) <EOL> } else { <EOL> assertFalse ( dstLink . isSymbolicLink ( ) ) <EOL> } <EOL> } <EOL> }


@ Test <EOL> fun copySameLinkDifferentRoute ( )

{ <EOL> for ( followLinks in listOf ( false , true ) ) { <EOL> val root = createTempDirectory ( ) . cleanupRecursively ( ) <EOL> val original = root . resolve ( "<STR_LIT>" ) . createFile ( ) <EOL> val srcLink = root . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( original ) ? : return <EOL> val dstLink = root . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( root ) ? . resolve ( "<STR_LIT>" ) ? : return <EOL> assertTrue ( srcLink . isSameFileAs ( dstLink ) ) <EOL> assertTrue ( dstLink . isSameFileAs ( srcLink ) ) <EOL> if ( ! followLinks ) { <EOL> srcLink . copyToRecursively ( dstLink , followLinks = followLinks ) <EOL> } else { <EOL> assertFailsWith < FileAlreadyExistsException > { <EOL> srcLink . copyToRecursively ( dstLink , followLinks = followLinks ) <EOL> } <EOL> } <EOL> assertTrue ( dstLink . isSymbolicLink ( ) ) <EOL> } <EOL> }


@ Test <EOL> fun copySameLinkDifferentRouteOverwrite ( )

{ <EOL> for ( followLinks in listOf ( false , true ) ) { <EOL> val root = createTempDirectory ( ) . cleanupRecursively ( ) <EOL> val original = root . resolve ( "<STR_LIT>" ) . createFile ( ) <EOL> val srcLink = root . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( original ) ? : return <EOL> val dstLink = root . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( root ) ? . resolve ( "<STR_LIT>" ) ? : return <EOL> if ( ! followLinks ) { <EOL> srcLink . copyToRecursively ( dstLink , followLinks = followLinks , overwrite = true ) <EOL> } else { <EOL> val error = assertFailsWith < NoSuchFileException > { <EOL> srcLink . copyToRecursively ( dstLink , followLinks = followLinks , overwrite = true ) <EOL> } <EOL> assertEquals ( srcLink . toString ( ) , error . file ) <EOL> assertFalse ( srcLink . exists ( LinkOption . NOFOLLOW_LINKS ) ) <EOL> assertFalse ( dstLink . exists ( LinkOption . NOFOLLOW_LINKS ) ) <EOL> } <EOL> } <EOL> }


@ Test <EOL> fun copySameFileDifferentRoute ( )

{ <EOL> val root = createTempDirectory ( ) . cleanupRecursively ( ) <EOL> val src = root . resolve ( "<STR_LIT:src>" ) . createFile ( ) <EOL> val dst = root . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( root ) ? . resolve ( "<STR_LIT:src>" ) ? : return <EOL> assertTrue ( src . isSameFileAs ( dst ) ) <EOL> assertTrue ( dst . isSameFileAs ( src ) ) <EOL> src . copyToRecursively ( dst , followLinks = false ) <EOL> }


@ Test <EOL> fun copyToSameFileDifferentRouteOverwrite ( )

{ <EOL> val root = createTempDirectory ( ) . cleanupRecursively ( ) <EOL> val src = root . resolve ( "<STR_LIT:src>" ) . createFile ( ) <EOL> val dst = root . resolve ( "<STR_LIT>" ) . tryCreateSymbolicLinkTo ( root ) ? . resolve ( "<STR_LIT:src>" ) ? : return <EOL> src . copyToRecursively ( dst , followLinks = false , overwrite = true ) <EOL> }


abstract fun flush ( ) : CompletableFuture < Void >


{ <EOL> future = service . schedule ( this :: flush , <NUM_LIT:0L> , TimeUnit . MILLISECONDS ) <EOL> }


protected override fun upSample ( tf : Ops , input : Operand < Float > ) : Operand < Float >

{ <EOL> return repeat ( tf , input , repeats = size , axis = <NUM_LIT:1> ) <EOL> }


{ <EOL> return "<STR_LIT>" <EOL> }


{ <EOL> impl ( ) <EOL> }


@ Test <EOL> fun testCleanerDestroyInChild ( )

{ <EOL> val worker = Worker . start ( ) <EOL> val called = AtomicBoolean ( false ) ; <EOL> var funBoxWeak : WeakReference < FunBox > ? = null <EOL> var cleanerWeak : WeakReference < Cleaner > ? = null <EOL> worker . execute ( TransferMode . SAFE , { <EOL> val funBox = FunBox { called . value = true } <EOL> funBoxWeak = WeakReference ( funBox ) <EOL> val cleaner = createCleaner ( funBox ) { it . call ( ) } <EOL> cleanerWeak = WeakReference ( cleaner ) <EOL> Pair ( called , cleaner ) <EOL> } ) { ( called , cleaner ) -> <EOL> assertFalse ( called . value ) <EOL> } . result <EOL> GC . collect ( ) <EOL> worker . execute ( TransferMode . SAFE , { } ) { GC . collect ( ) } . result <EOL> performGCOnCleanerWorker ( ) <EOL> assertNull ( cleanerWeak ! ! . value ) <EOL> assertTrue ( called . value ) <EOL> assertNull ( funBoxWeak ! ! . value ) <EOL> worker . requestTermination ( ) . result <EOL> }