1

我正在将 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类型写续行?只是通过++操作?

4

1 回答 1

4

只需将几个"- 封闭的字符串彼此相邻,中间有空格。这适用于字符串和二进制文件:

1> <<"foo\n"
     "bar">>.
<<"foo\nbar">>

2> "foo\n"
   "bar".
"foo\nbar"

字符串/二进制文件在编译时加入。

于 2012-12-12T10:23:03.313 回答