146 lines
6.3 KiB
EmacsLisp
146 lines
6.3 KiB
EmacsLisp
;;; verilog-align-ports-test.el --- Tests for verilog-align-ports -*- lexical-binding: t; -*-
|
|
|
|
;;; Commentary:
|
|
;; ERT tests for verilog-align-ports.
|
|
|
|
;;; Code:
|
|
|
|
(require 'ert)
|
|
|
|
(defconst verilog-align-ports-test--dir
|
|
(file-name-directory (or load-file-name buffer-file-name)))
|
|
|
|
(load-file (expand-file-name "verilog-align-ports.el"
|
|
verilog-align-ports-test--dir))
|
|
|
|
(ert-deftest verilog-align-ports-aligns-block ()
|
|
(let* ((input (concat
|
|
(mapconcat
|
|
#'identity
|
|
'("module fifo_sync #("
|
|
" parameter integer FifoWriteDepth = 2048,"
|
|
" parameter integer DataWidth = 32,"
|
|
" parameter integer WrDataCountWidth = $clog2(FifoWriteDepth)+1,"
|
|
" parameter integer RdDataCountWidth = 4"
|
|
") ("
|
|
" input wire rst_i, // rst,"
|
|
" input wire clk_i, // wr_clk,"
|
|
" input wire wr_en_i, // wr_en,"
|
|
" input wire [DataWidth-1:0] d_i, // din,"
|
|
" output logic full_o, // full,"
|
|
" output logic [WrDataCountWidth-1:0] wr_data_count_o, // wr_data_count,"
|
|
" input wire rd_en_i, // rd_en,"
|
|
" output [DataWidth-1:0] d_o, // dout,"
|
|
" output empty_o,// empty,"
|
|
" output logic valid_o // data_valid"
|
|
");")
|
|
"\n")
|
|
"\n"))
|
|
(expected (concat
|
|
(mapconcat
|
|
#'identity
|
|
'("module fifo_sync #("
|
|
" parameter integer FifoWriteDepth = 2048,"
|
|
" parameter integer DataWidth = 32,"
|
|
" parameter integer WrDataCountWidth = $clog2(FifoWriteDepth)+1,"
|
|
" parameter integer RdDataCountWidth = 4"
|
|
") ("
|
|
" input wire rst_i, // rst,"
|
|
" input wire clk_i, // wr_clk,"
|
|
" input wire wr_en_i, // wr_en,"
|
|
" input wire [DataWidth-1:0] d_i, // din,"
|
|
" output logic full_o, // full,"
|
|
" output logic [WrDataCountWidth-1:0] wr_data_count_o, // wr_data_count,"
|
|
" input wire rd_en_i, // rd_en,"
|
|
" output [DataWidth-1:0] d_o, // dout,"
|
|
" output empty_o, // empty,"
|
|
" output logic valid_o // data_valid"
|
|
");")
|
|
"\n")
|
|
"\n")))
|
|
(with-temp-buffer
|
|
(insert input)
|
|
(goto-char (point-min))
|
|
(search-forward "input wire clk_i")
|
|
(beginning-of-line)
|
|
(verilog-align-ports)
|
|
(should (string= (buffer-string) expected)))))
|
|
|
|
(ert-deftest verilog-align-ports-instantiation-aligns-block ()
|
|
(let* ((input (concat
|
|
(mapconcat
|
|
#'identity
|
|
'("fifo_sync #("
|
|
" .FifoWriteDepth(FifoWriteDepth),"
|
|
" .DataWidth(DataWidth),"
|
|
" .DataCountWidth(WrDataCountW),"
|
|
" .RdDataCountWidth(RdDataCountW)"
|
|
") dut ("
|
|
" .rst_i (rst), //rst"
|
|
" .clk_i (clk),"
|
|
" .wr_en_i (wr_en_i),"
|
|
" .d_i (d_i), // di"
|
|
" .full_o, // full"
|
|
" .data_count_o (wr_data_count_o),"
|
|
" .rd_en_i (rd_en_i),"
|
|
" .d_o () , // do"
|
|
" .empty_o , // empty"
|
|
" .valid_o (valid_o)"
|
|
");")
|
|
"\n")
|
|
"\n"))
|
|
(expected (concat
|
|
(mapconcat
|
|
#'identity
|
|
(list
|
|
"fifo_sync #("
|
|
" .FifoWriteDepth(FifoWriteDepth),"
|
|
" .DataWidth(DataWidth),"
|
|
" .DataCountWidth(WrDataCountW),"
|
|
" .RdDataCountWidth(RdDataCountW)"
|
|
") dut ("
|
|
(concat " .rst_i" (make-string 8 ?\s) "(rst),"
|
|
(make-string 13 ?\s) "//rst")
|
|
(concat " .clk_i" (make-string 8 ?\s) "(clk),")
|
|
(concat " .wr_en_i" (make-string 6 ?\s) "(wr_en_i),")
|
|
(concat " .d_i" (make-string 10 ?\s) "(d_i),"
|
|
(make-string 13 ?\s) "// di")
|
|
(concat " .full_o," (make-string 25 ?\s) "// full")
|
|
(concat " .data_count_o" (make-string 1 ?\s)
|
|
"(wr_data_count_o),")
|
|
(concat " .rd_en_i" (make-string 6 ?\s) "(rd_en_i),")
|
|
(concat " .d_o" (make-string 10 ?\s) "(),"
|
|
(make-string 16 ?\s) "// do")
|
|
(concat " .empty_o," (make-string 24 ?\s) "// empty")
|
|
(concat " .valid_o" (make-string 6 ?\s) "(valid_o)")
|
|
");")
|
|
"\n")
|
|
"\n")))
|
|
(with-temp-buffer
|
|
(insert input)
|
|
(goto-char (point-min))
|
|
(search-forward ".clk_i")
|
|
(beginning-of-line)
|
|
(should (verilog-align-ports-instantiation))
|
|
(should (string= (buffer-string) expected)))))
|
|
|
|
(ert-deftest verilog-align-ports-instantiation-returns-nil-outside ()
|
|
(with-temp-buffer
|
|
(insert (concat
|
|
(mapconcat
|
|
#'identity
|
|
'("fifo_sync #() dut ("
|
|
" .rst_i (rst),"
|
|
" .clk_i (clk)"
|
|
");")
|
|
"\n")
|
|
"\n"))
|
|
(goto-char (point-min))
|
|
(search-forward "dut (")
|
|
(beginning-of-line)
|
|
(should (not (verilog-align-ports-instantiation)))))
|
|
|
|
(provide 'verilog-align-ports-test)
|
|
|
|
;;; verilog-align-ports-test.el ends here
|