系统相关
首页 > 系统相关> > sbt reference manual中Mapping Files里的示例代码在windows平台运行出错的修改

sbt reference manual中Mapping Files里的示例代码在windows平台运行出错的修改

作者:互联网

原文链接:https://www.scala-sbt.org/1.x/docs/Mapping-Files.html

原文中有6段代码,其中第1,2,6段代码在windows上是跑不对的。现在将错误原因和修改代码一并给出:

第1,2段代码出错原因一样,是目录分隔符的原因:

第6段代码出错原因除了目录分割符问题之外,还因为在expected的定义里多了两个括号。

 

修改后能跑的6段代码集合如下:

import Path.relativeTo
val files: Seq[File] = file("/a/b/C.scala") :: Nil
val baseDirectories: Seq[File] = file("/a") :: Nil
val mappings: Seq[(File,String)] = files pair relativeTo(baseDirectories)

val expected = (file("/a/b/C.scala") -> "b\\C.scala") :: Nil
assert( mappings == expected )

import Path.rebase
val files2: Seq[File] = file("/a/b/C.scala") :: Nil
val baseDirectories2: File = file("/a")
val mappings2: Seq[(File,String)] = files2 pair rebase(baseDirectories2, "pre/")

val expected2 = (file("/a/b/C.scala") -> "pre/b\\C.scala") :: Nil
assert( mappings2 == expected2 )

val files3: Seq[File] = file("/a/b/C.scala") :: Nil
val baseDirectories3: Seq[File] = file("/a") :: Nil
val newBase3: File = file("/new/base")
val mappings3: Seq[(File,File)] = files3 pair rebase(baseDirectories3, newBase3)

val expected3 = (file("/a/b/C.scala") -> file("/new/base/b/C.scala") ) :: Nil
assert( mappings3 == expected3 )

import Path.flat
val files4: Seq[File] = file("/a/b/C.scala") :: Nil
val mappings4: Seq[(File,String)] = files4 pair flat

val expected4 = (file("/a/b/C.scala") -> "C.scala" ) :: Nil
assert( mappings4 == expected4 )

val files5: Seq[File] = file("/a/b/C.scala") :: Nil
val newBase5: File = file("/new/base")
val mappings5: Seq[(File,File)] = files5 pair flat(newBase5)

val expected5 = (file("/a/b/C.scala") -> file("/new/base/C.scala") ) :: Nil
assert( mappings5 == expected5 )

val files6: Seq[File] = file("/a/b/C.scala") :: file("/zzz/D.scala") :: Nil
val baseDirectories6: Seq[File] = file("/a") :: Nil
val mappings6: Seq[(File,String)] = files6 pair ( relativeTo(baseDirectories6) | flat )

val expected6 = (file("/a/b/C.scala") -> "b\\C.scala") :: (file("/zzz/D.scala") -> "D.scala") :: Nil
assert( mappings6 == expected6 )

  

标签:Files,sbt,val,scala,File,示例,Seq,file,Nil
来源: https://www.cnblogs.com/decentcan/p/14735455.html