未验证 提交 8e670a35 编写于 作者: 梦境迷离's avatar 梦境迷离 提交者: GitHub

add test (#3)

* add test

* add readme
上级 042a677a
name: Scala CI
name: Build
on:
push:
......@@ -22,11 +22,12 @@ jobs:
with:
java-version: 1.8
- name: Publish Local
run: sbt +publishLocal
- name: Build
run: sbt +compile
- name: Run Test
run: sbt test
- name: Publish Local
run: sbt publishLocal
\ No newline at end of file
......@@ -4,4 +4,6 @@
/target/
/target/scala-2.13/classes/
/target/scala-2.13/test-classes/
.idea/
\ No newline at end of file
.idea/
*.iml
.bsp
\ No newline at end of file
# scala-macro-tools
# scala-macro-tools [![Build](https://github.com/jxnu-liguobin/scala-macro-tools/actions/workflows/ScalaCI.yml/badge.svg)](https://github.com/jxnu-liguobin/scala-macro-tools/actions/workflows/ScalaCI.yml)
Motivation
--
scala macro and abstract syntax tree learning code.
# @toString
- Argument
- Note
- `verbose` Whether to enable detailed log.
- `withFieldName` Whether to include the name of the field in the toString.
- `withInternalField` Whether to include the fields defined within a class.
......@@ -22,7 +25,38 @@ class TestClass(val i: Int = 0, var j: Int) {
println(new TestClass(1, 2));
```
| withInternalField / withFieldName | false |true
|withInternalField / withFieldName| false |true
| ---- | ---- |----|
|false|```TestClass(1, 2)``` |```TestClass(i=0, j=2)```|
|true|```TestClass(1, 2, 0, hello, world)```|```TestClass(i=1, j=2, y=0, z=hello, x=world)```|
\ No newline at end of file
|true|```TestClass(1, 2, 0, hello, world)```|```TestClass(i=1, j=2, y=0, z=hello, x=world)```|
# How to use
Add library dependency
```scala
"io.github.jxnu-liguobin" %% "scala-macro-tools" % "<VERSION>"
```
The artefacts have been uploaded to Maven Central. Alternatively, they are also available on the GitHub registry.
| Library Version | Scala 2.11 | Scala 2.12 | Scala 2.13 |
|---------|------------|------------|------------|
|0.0.1|-|-|[![Maven Central](https://img.shields.io/maven-central/v/io.github.jxnu-liguobin/scala-macro-tools_2.13.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22io.github.jxnu-liguobin%22%20AND%20a:%22scala-macro-tools_2.13%22)|
Importing the library into your build system (e.g gradle, sbt), is not enough. You need to follow an extra step.
| Scala 2.11 | Scala 2.12 | Scala 2.13 |
|------------|-------------|------------|
| Import macro paradise plugin | Import macro paradise plugin | Enable compiler flag `-Ymacro-annotations` required |
```scala
addCompilerPlugin("org.scalamacros" % "paradise_<your-scala-version>" % "<plugin-version>")
```
Where `<your-scala-version>` must be the full scala version. For example 2.12.13, and not 2.12.
If that doesn't work, google for alternatives.
In version scala`2.13.x`, the functionality of macro paradise has been included in the scala compiler directly.
However, you must still enable the compiler flag `-Ymacro-annotations`. Please see examples from `examples212` sub-project.
\ No newline at end of file
......@@ -37,4 +37,32 @@ lazy val root = (project in file("."))
commitNextVersion,
pushChanges
)
).settings(Publishing.publishSettings)
).settings(Publishing.publishSettings).settings(
libraryDependencies ++= (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, n)) => getParadise(n)
case _ => None
}).fold(Seq.empty[ModuleID])(f => Seq(compilerPlugin(f)))
)
lazy val `examples213` = (project in file("examples213")).settings(scalaVersion := scala213)
.settings(libraryDependencies ++= Seq(
"io.github.jxnu-liguobin" %% "scala-macro-tools" % (version in ThisBuild).value,
)).settings(Compile / scalacOptions += "-Ymacro-annotations")
lazy val `examples212` = (project in file("examples212")).settings(scalaVersion := scala212)
.settings(libraryDependencies ++= Seq(
"io.github.jxnu-liguobin" %% "scala-macro-tools" % (version in ThisBuild).value,
)).settings(
libraryDependencies ++= (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, n)) => getParadise(n)
case _ => None
}).fold(Seq.empty[ModuleID])(f => Seq(compilerPlugin(f))))
def getParadise(n: Long): Option[ModuleID] = {
if (n == 12) Option("org.scalamacros" % s"paradise_$scala212" % "2.1.1")
else if (n == 11) Option("org.scalamacros" % s"paradise_$scala211" % "2.1.1") else None
None
}
package io.github.dreamylost
/**
*
* @author 梦境迷离
* @since 2021/6/16
* @version 1.0
*/
object Main extends App {
@toString(withInternalField = true, withFieldName = true)
class TestClass(val i: Int = 0, var j: Int) {
val y: Int = 0
var z: String = "hello"
var x: String = "world"
}
val s = new TestClass(1, 2).toString
println(s)
}
package io.github.dreamylost
/**
*
* @author 梦境迷离
* @since 2021/6/16
* @version 1.0
*/
object Main extends App {
@toString(withInternalField = true, withFieldName = true)
class TestClass(val i: Int = 0, var j: Int) {
val y: Int = 0
var z: String = "hello"
var x: String = "world"
}
val s = new TestClass(1, 2).toString
println(s)
}
......@@ -37,8 +37,8 @@ object Publishing {
homepage := Some(url("https://github.com/jxnu-liguobin")),
scmInfo := Some(
ScmInfo(
url("https://github.com/bitlap/scala-macro-tools"),
"scm:git@github.com:bitlap/scala-macro-tools.git"
url("https://github.com/jxnu-liguobin/scala-macro-tools"),
"scm:git@github.com:jxnu-liguobin/scala-macro-tools.git"
))
)
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册