mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-11-04 13:29:12 +00:00 
			
		
		
		
	libparse: LibertyExpression unit test
This commit is contained in:
		
							parent
							
								
									21e68ec9be
								
							
						
					
					
						commit
						c7a3abbcc4
					
				
					 1 changed files with 88 additions and 0 deletions
				
			
		
							
								
								
									
										88
									
								
								tests/unit/techmap/libparseTest.cc
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										88
									
								
								tests/unit/techmap/libparseTest.cc
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,88 @@
 | 
			
		|||
#include <gtest/gtest.h>
 | 
			
		||||
#include "passes/techmap/libparse.h"
 | 
			
		||||
 | 
			
		||||
YOSYS_NAMESPACE_BEGIN
 | 
			
		||||
 | 
			
		||||
namespace RTLIL {
 | 
			
		||||
 | 
			
		||||
	class TechmapLibparseTest : public testing::Test {
 | 
			
		||||
	protected:
 | 
			
		||||
		TechmapLibparseTest() {
 | 
			
		||||
			if (log_files.empty()) log_files.emplace_back(stdout);
 | 
			
		||||
		}
 | 
			
		||||
		void checkAll(std::initializer_list<std::string> expressions, std::string expected) {
 | 
			
		||||
			for (const auto& e : expressions) {
 | 
			
		||||
				auto helper = LibertyExpression::Lexer(e);
 | 
			
		||||
				auto tree_s = LibertyExpression::parse(helper).str();
 | 
			
		||||
				EXPECT_EQ(tree_s, expected);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	};
 | 
			
		||||
	TEST_F(TechmapLibparseTest, LibertyExpressionSpace)
 | 
			
		||||
	{
 | 
			
		||||
		checkAll({
 | 
			
		||||
			"x",
 | 
			
		||||
			"x ",
 | 
			
		||||
			" x",
 | 
			
		||||
			" x ",
 | 
			
		||||
			"  x ",
 | 
			
		||||
		}, "(pin \"x\")");
 | 
			
		||||
 | 
			
		||||
		checkAll({
 | 
			
		||||
			"x y",
 | 
			
		||||
			" x y ",
 | 
			
		||||
			"x (y)",
 | 
			
		||||
			" x (y) ",
 | 
			
		||||
			"(x) y",
 | 
			
		||||
			" (x) y ",
 | 
			
		||||
 | 
			
		||||
			"x & y",
 | 
			
		||||
			"x&y",
 | 
			
		||||
			"x &y",
 | 
			
		||||
			"x& y",
 | 
			
		||||
			" x&y ",
 | 
			
		||||
			"x & (y)",
 | 
			
		||||
			"x&(y)",
 | 
			
		||||
			"x &(y)",
 | 
			
		||||
			"x& (y)",
 | 
			
		||||
			" x&(y) ",
 | 
			
		||||
			"(x) & y",
 | 
			
		||||
			"(x)&y",
 | 
			
		||||
			"(x) &y",
 | 
			
		||||
			"(x)& y",
 | 
			
		||||
			" (x)&y ",
 | 
			
		||||
		}, "(and (pin \"x\")\n"
 | 
			
		||||
		   "     (pin \"y\"))"
 | 
			
		||||
		);
 | 
			
		||||
 | 
			
		||||
		checkAll({
 | 
			
		||||
			"x ^ y",
 | 
			
		||||
			"x^y",
 | 
			
		||||
			"x ^y",
 | 
			
		||||
			"x^ y",
 | 
			
		||||
			" x^y ",
 | 
			
		||||
		}, "(xor (pin \"x\")\n"
 | 
			
		||||
		   "     (pin \"y\"))"
 | 
			
		||||
		);
 | 
			
		||||
		checkAll({
 | 
			
		||||
			"x !y",
 | 
			
		||||
			" x !y ",
 | 
			
		||||
			"x & !y",
 | 
			
		||||
			"x&!y",
 | 
			
		||||
			"x &!y",
 | 
			
		||||
			"x& !y",
 | 
			
		||||
			" x&!y ",
 | 
			
		||||
			"x y'",
 | 
			
		||||
			" x y' ",
 | 
			
		||||
			"x & y'",
 | 
			
		||||
			"x&y'",
 | 
			
		||||
			"x &y'",
 | 
			
		||||
			"x& y'",
 | 
			
		||||
			" x&y' ",
 | 
			
		||||
		}, "(and (pin \"x\")\n"
 | 
			
		||||
		   "     (not (pin \"y\")))"
 | 
			
		||||
		);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
YOSYS_NAMESPACE_END
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue