我正在将hglib-python转换为hglib-erlang。在文件test-diff.py中,python代码如下:
import common
class test_diff(common.basetest):
def test_basic(self):
self.append('a', 'a\n')
self.client.add('a')
diff1 = """diff -r 000000000000 a
--- /dev/null
+++ b/a
@@ -0,0 +1,1 @@
+a
"""
self.assertEquals(diff1, self.client.diff(nodates=True))
self.assertEquals(diff1, self.client.diff(['a'], nodates=True))
rev0, node0 = self.client.commit('first')
diff2 = """diff -r 000000000000 -r %s a
--- /dev/null
+++ b/a
@@ -0,0 +1,1 @@
+a
""" % node0[:12]
self.assertEquals(diff2, self.client.diff(change=rev0, nodates=True))
self.append('a', 'a\n')
rev1, node1 = self.client.commit('second')
diff3 = """diff -r %s a
--- a/a
+++ b/a
@@ -1,1 +1,2 @@
a
+a
""" % node0[:12]
self.assertEquals(diff3, self.client.diff(revs=[rev0], nodates=True))
diff4 = """diff -r %s -r %s a
--- a/a
+++ b/a
@@ -1,1 +1,2 @@
a
+a
""" % (node0[:12], node1[:12])
self.assertEquals(diff4, self.client.diff(revs=[rev0, rev1], nodates=True))
对于我的hglib-erlang,第一个函数转换如下:
diff_test_a()->
teardown(push),
setup(push),
{ok,Pid} = emercurial_client:start_link('none','UTF-8','none',true),
append("a","a\n"),
true = emercurial_client:add(Pid,#add{files=['a']}),
Diff1 =
<<"diff -r 000000000000 a\n--- /dev/null\n+++ b/a\n@@ -0,0 +1,1 @@\n+a\n">>,
Result = emercurial_client:diff(Pid,#diff{nodates=true}),
error_logger:info_report([client_tests_diff_test_1,Result]),
?assertMatch(Diff1,Result).
以上Diff1
匹配行太长,erlang binary
类型的续行是什么?
另外,如何为erlang list
类型编写行继续?只是通过++
操作?
答案 0 :(得分:4)
只需将几个"
- 封闭的字符串放在一起,两者之间有空格。这适用于股和二进制文件:
1> <<"foo\n"
"bar">>.
<<"foo\nbar">>
2> "foo\n"
"bar".
"foo\nbar"
字符串/二进制文件在编译时加入。